python - 尝试使用 python 从 azure 函数触发 url,错误地说“没有 $return 绑定返回非无值”
问题描述
下面是代码,
import logging
import json
import urllib.request
import urllib.parse
import azure.functions as func
def main(myblob: func.InputStream):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")
response = urllib.request.urlopen("http://example.com:5000/processing")
return {
'statusCode': 200,
'body': json.dumps(response.read().decode('utf-8'))
}
错误:结果:失败异常:RuntimeError:没有 $return 绑定的函数“abc”返回非无值堆栈:文件“/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py ",第 341 行,在 _handle__invocation_request f'function {fi.name!r} 中没有 $return 绑定'。相同的代码在 lambda 中有效。请帮助我调试 azure 函数。
函数.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "sourcemetadata/{name}",
"connection": "AzureWebJobsStorage"
}
]
}
解决方案
在 Azure 函数中,如果return
在函数应用代码中使用,则表示要使用输出绑定。但是您没有在 function.json 中定义它。请定义它。有关更多详细信息,请参阅此处和此处
例如
我使用带有 blob 触发器的进程 blob 并将消息发送到带有队列输出绑定的 azure 队列
- 函数.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "test/{name}.csv",
"connection": "AzureWebJobsStorage"
},
{
"name": "$return",
"direction": "out",
"type": "queue",
"queueName": "outqueue",
"connection": "AzureWebJobsStorage"
}
]
}
- 代码
async def main(myblob: func.InputStream) :
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n")
return "OK"
推荐阅读
- wordpress - 为什么我的数据库查询代码在 PHP 7.3 中失败?但它在 php7.0 中运行良好
- javascript - Echart图形不变色
- mysql - 增强对具有数百万条记录的表的不同查询
- pandas - pandas pivot_table:我可以在输出中显示小计吗?
- c - 如何从指针中减去字符数组?
- javascript - 谷歌表格脚本自动定位具有今天日期的单元格,复制整行并通过电子邮件发送
- c++ - 在自定义 ComboBox 中绘制文本
- flutter - 将列表中的颜色传递给小部件 - Flutter
- excel - 在 Excel VBA 中正确编写公式
- spring-boot - Kubernetes 发现定位器上的 Spring Cloud Gateway 使用 pod 端口而不是服务端口