python - Azure函数: System. InvalidOperationException:存储帐户连接字符串'不存在

标签 python azure azure-functions azure-storage

我编写了一个azure函数,目前azure函数充当Webhook Consumer。该函数的工作是读取 Webhook 事件并保存到 Azure 存储中。 我正在使用 HTTP 触发器模板来完成工作。我能够从 Webhook 接收事件,但是当我尝试写入 Azure 存储时,出现以下错误。

我尝试了此post中提到的选项,但不幸的是仍然遇到同样的错误。

System.InvalidOperationException: Storage account connection string 'AzureWebJobs<AzureStorageAccountName>' does not exist. Make sure that it is a defined App Setting.

下面是我的function.json文件

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "blob",
      "name": "outputblob",
      "path": "test/demo",
      "direction": "out",
      "connection": "<AzureStorageAccountName>"
    }    
  ]
}

init.py

import logging

import azure.functions as func

def main(req: func.HttpRequest,outputblob: func.Out[str]) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = 'some_name'
    if not name:
        try:
            req_body = 'req_body_test'#req.get_json()
        except ValueError:
            pass
    else:
        name = 'name'#req_body.get('name')
    
    print(str(req.get_json()))

    outputblob.set(str(req.get_json()))

最佳答案

enter image description here

请确保您已将连接字符串添加到本地的 local.settings.json 或 Azure 上的配置设置。

请测试以下代码和设置文件:

__init__.py

import logging

import azure.functions as func


def main(req: func.HttpRequest,outputblob: func.Out[func.InputStream]) -> func.HttpResponse:
    outputblob.set("this is a test.")
    return func.HttpResponse(
            "Test.",
            status_code=200
    )

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    },
    {
      "name": "outputblob",
      "type": "blob",
      "path": "test/demo",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "out"
    }
  ]
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "MyStorageConnectionAppSetting":"DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net"
  }
}

在 azure 上:

enter image description here

关于python - Azure函数: System. InvalidOperationException:存储帐户连接字符串'不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66437089/

相关文章:

python - 以与 Python 2 和 Python 3 无关的方式重新引发异常

python - 如何提示 Sympy 逆高斯方程的积分

azure - SSL 绑定(bind)在 Azure 函数上不起作用

node.js - Node-Powershell Azure 函数应用程序不会读取命令

Azure Kubernetes 服务节点无法访问互联网

azure - Azure 函数是否支持 Cosmos DB 与 Mongo Api 的绑定(bind)?除了使用 MongoClient 之外还有其他解决方法吗

Python 没有创建一个新的干净实例?

python - 在 GAE 数据存储中存储有向、加权、完整的图

azure - 自动 Azure 密码更改

AzureApp HTTP 错误 500.30 - ASP.NET Core 应用程序无法启动