我有一個(gè)簡單的 Azure 函數(shù),定義如下:import loggingimport cdsapiimport azure.functions as funcimport sysdef main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function is about to process request.') try: cds = cdsapi.Client() cds.url="urlgoeshere" cds.key="keygoeshere" cds.retrieve("reanalysis-era5-pressure-levels", { "variable": "temperature", "pressure_level": "1000", "product_type": "reanalysis", "year": "2008", "month": "01", "day": "01", "time": "12:00", "format": "grib" },"download.grib") return func.HttpResponse( "This HTTP triggered function executed successfully.", status_code=200 ) except: logging.info(" error!", sys.exc_info()[0], "occurred.")我的目的是在命令下檢索數(shù)據(jù)cds.retrieve。當(dāng)我從 Visual Studio 代碼中調(diào)試它時(shí),它工作得很好。但是當(dāng)我通過 VS code 將它部署到 Azure 函數(shù)時(shí),它根本不起作用。我收到以下錯(cuò)誤:2020-09-02T16:01:45Z [Information] Executing 'Functions.azure-cds' (Reason='This function was programmatically called via the host APIs.', Id=ae0df178-f726-461e-aca7-8ada6995feaa)2020-09-02T16:01:45Z [Verbose] Sending invocation id:ae0df178-f726-461e-aca7-8ada6995feaa2020-09-02T16:01:45Z [Verbose] Posting invocation id:ae0df178-f726-461e-aca7-8ada6995feaa on workerId:e365cae7-bb7c-4f14-92b9-82b5cb77334b2020-09-02T16:01:45Z [Information] Python HTTP trigger function is about to process request.2020-09-02T16:01:45Z [Error] Executed 'Functions.azure-cds' (Failed, Id=ae0df178-f726-461e-aca7-8ada6995feaa, Duration=9ms)在requirements.txt我添加了依賴項(xiàng):azure-functionscdsapi似乎第 3 方 API 需要在 azure 門戶中以某種方式進(jìn)行調(diào)整,感謝解決此問題的任何幫助。
1 回答

侃侃無極
TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊
為了做到這一點(diǎn),我必須編輯cdsapi
package.json 中的源代碼。這是因?yàn)?API 默認(rèn)設(shè)置為在本地計(jì)算機(jī)中搜索/.cdsapirc
文件。url
這是存儲(chǔ)和的文件key
。此環(huán)境和文件無法在云azure功能中重現(xiàn)。我所做的只是在類內(nèi)部的方法中設(shè)置url
和key
為空字符串,然后將它們設(shè)置為適當(dāng)?shù)闹怠?code>__init__Client
添加回答
舉報(bào)
0/150
提交
取消