簡體   English   中英

Azure Blob 觸發器 Python Function 寫入 CosmosDB 錯誤

[英]Azure Blob Trigger Python Function to Write To CosmosDB Error

I have JSON documents being uploaded into an Azure Blob Container and I have written an Azure Python Function to write the JSON into CosmosDB. 觸發工作正常,但我得到一個錯誤。 這是 Python function:

import logging
import azure.functions as func

def main(myblob: func.InputStream, doc: func.Out[func.Document]):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")
    
    json_data = myblob.read()
    try:
        # Store output data using Cosmos DB output binding
        doc.set(func.Document.from_json(json_data))
    except Exception as e:
        logging.info(f"Error: {e}")
        print('Error:')
        print(e)

這是 function.json 文件:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "cloud-save-blob-container/{name}",
      "connection": "cloudsavestorage_STORAGE"
    },
    {
      "type": "cosmosDB",
      "name": "userJson",
      "databaseName": "ToDoList",
      "collectionName": "Items",
      "createIfNotExists": false,
      "connectionStringSetting": "MyCosmosDBConnectionString",
      "direction": "out"
    }
  ],
  "disabled": false
}

這是我在 Azure 門戶中看到的錯誤:

Result: Failure Exception: FunctionLoadError: cannot load the JsonBlobTrigger1 function: the following parameters are declared in Python but not in function.json: {'doc'} Stack: File "/azure-functions-host/workers/python/3.8/LINUX /X64/azure_functions_worker/dispatcher.py”,第 290 行,在 _handle__function_load_request self._functions.add_function(文件“/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/functions.py”,第 112 行,在 add_function 中引發 FunctionLoadError(

感謝您的幫助。

我已經解決了這個問題,我的 Python Function 被觸發並將數據放入 Cosmos DB,就像我想要的那樣。 問題出在我的 Python 代碼上。 我在兩個應該是“userJson”的地方有“doc”。 一,在“def main(...):”行中,再次在“try:”塊中,“doc.set(...)”,它與function.Z466DEEC76ECDF5FCA65D3875中的Output綁定名稱不匹配。 一旦我將兩次出現的“doc”更改為“userJson”,它就起作用了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM