Azure Functions v2 Python - CosmosDB输入装饰器

brgchamk  于 2023-10-22  发布在  Python
关注(0)|答案(1)|浏览(127)

我正在尝试使用python v2编程模型在azure函数应用程序中编写一个非常基本的函数。我想要它做的就是连接到一个CosmosDB帐户,并返回一个名为“systems”的给定容器中列出的所有文档。它将在将来返回一组经过过滤的文档,但现在只有一个文档,因此不需要过滤。
这是目前基于适配these examples from azure的功能:

import azure.functions as func
import logging
import json

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

@app.function_name(name="system")
@app.route(route="system")
@app.cosmos_db_input(arg_name="documents", 
                     database_name="database",
                     container_name="systems",
                     connection_string_setting="DATABASE_CONNECTION_STRING")
def system(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    return func.HttpResponse(
        json.dumps(documents),
        status_code=200
    )

当我尝试使用Azure函数核心工具(核心工具版本:4.0.5198提交哈希:N/A(64-bit)函数类型:4.21.1.20667
我得到下面的错误,我不能为我的生活弄清楚什么信息,我需要给它的“连接”的论点给予。基于所有的Azure演示,我应该只需要提供local.settings.json文件中的连接字符串,名称为DATABASE_CONNECTION_STRING。

[2023-10-02T10:11:56.430Z] Worker failed to index functions
[2023-10-02T10:11:56.432Z] Result: Failure
Exception: TypeError: BindingApi.cosmos_db_input() missing 1 required positional argument: 'connection'        
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 338, in _handle__functions_metadata_request
    fx_metadata_results = self.index_functions(function_path)
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 607, in index_functions
    indexed_functions = loader.index_function_app(function_path)
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 44, in call
    return func(*args, **kwargs)
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10\WINDOWS\X64\azure_functions_worker\loader.py", line 151, in index_function_app
    imported_module = importlib.import_module(module_name)
  File "C:\Users\gcookman\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\gcookman\Code\KPMG-DAI-API\function_app.py", line 9, in <module>
    @app.cosmos_db_input(arg_name="documents",

感谢任何帮助或指导:)

a7qyws3x

a7qyws3x1#

你有一个混合的。connection_string_setting用于旧扩展,而container_name用于新/当前扩展。
根据错误,你似乎在使用新的。
connection_string_setting更改为connection。函数文档似乎有点不对劲(https://learn.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=python-v2%2Cisolated-process%2Cnodejs-v4% 2Cextensionv 4 &pivots=programming-language-python#configuration),因为它们没有_,但名称是正确的。

相关问题