[英]Azure function: System.InvalidOperationException: Storage account connection string 'does not exist
I have written an azure function, currently the azure function is acting as Webhook Consumer.我写了一个 azure function,目前 azure ZC1C425268E687385D1AB507 充当 Consumer。 The job of the function is to read Webhook events and save into azure storage.
function 的工作是读取 Webhook 事件并保存到 azure 存储中。 I am using an HTTP trigger template to get the job done.
我正在使用 HTTP 触发模板来完成工作。 I am able to receive the events from the Webhook, but when I try to write to azure storage it is giving me below error.
我能够从 Webhook 接收事件,但是当我尝试写入 azure 存储时,它给了我以下错误。
I tried the option mentioned in this post , but no luck still getting the same error.我尝试了这篇文章中提到的选项,但没有运气仍然得到同样的错误。
System.InvalidOperationException: Storage account connection string 'AzureWebJobs<AzureStorageAccountName>' does not exist. Make sure that it is a defined App Setting.
Below is my function.json file下面是我的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初始化.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()))
Please make sure you have already add the connection string to the local.settings.json on local or configuration settings on azure.请确保您已将连接字符串添加到本地或 azure 上的配置设置上的 local.settings.json。
Please test below code and settings files:请测试以下代码和设置文件:
__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"
}
}
On azure:在 azure 上:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.