我有一個簡單的 Azure 函數,定義如下: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.")我的目的是在命令下檢索數據cds.retrieve。當我從 Visual Studio 代碼中調試它時,它工作得很好。但是當我通過 VS code 將它部署到 Azure 函數時,它根本不起作用。我收到以下錯誤: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我添加了依賴項:azure-functionscdsapi似乎第 3 方 API 需要在 azure 門戶中以某種方式進行調整,感謝解決此問題的任何幫助。
1 回答

侃侃無極
TA貢獻2051條經驗 獲得超10個贊
為了做到這一點,我必須編輯cdsapi
package.json 中的源代碼。這是因為 API 默認設置為在本地計算機中搜索/.cdsapirc
文件。url
這是存儲和的文件key
。此環境和文件無法在云azure功能中重現。我所做的只是在類內部的方法中設置url
和key
為空字符串,然后將它們設置為適當的值。__init__
Client
添加回答
舉報
0/150
提交
取消