如何解决Azure 函数触发 http Azure 函数
FUNCTION_URL = "https://functionapp.azurewebsites.net/api/functionname?code={function_key_secret}"
FUNCTION_URL_PAYLOAD = "&name={name}&number={number}"
def trigger_function(name,number):
function_key_secret = get_keyvault_secret(secret_item_name='function-key')
url = FUNCTION_URL.format(function_key_secret=function_key_secret)
payload = FUNCTION_URL_PAYLOAD.format(name=name,number=number)
try:
azure_response = requests.request(method='POST',url=f"{url}{payload}")
except requests.exceptions.RequestException as error:
logging.error(
'Failed to make POST to the Function: %s',error)
我正在使用此方法触发第二个 Azure 函数,该函数设置为在 HTTP 请求时触发。但是,我认为它不起作用。 HTTP 触发的函数没有显示任何成功执行计数,而初始函数的成功执行计数正在上升。我还可以在日志中看到初始功能正常工作。
对于场景: 功能 1 = 更新 cosmosdb 表并触发功能 2 Function2(HTTP 触发器)= 使用来自 Function1 的输入(名称和编号)将数据发送到 Azure 之外的服务。
我可以手动触发 function2,在日志中我会看到它有效。然而,当 Function1 执行上述代码时,我没有看到相同的日志出现。 不要介意 get_keyvault_secret 方法。我也在 Function1 内部使用它,它运行完美。顺便说一下,我的日志输出没有错误。
Function.json:
{
"scriptFile": "__init__.py","bindings": [
{
"authLevel": "function","type": "httpTrigger","direction": "in","name": "req","methods": [
"get","post"
]
},{
"type": "http","direction": "out","name": "$return"
}
]
}
然而,每当从 Function1 触发 Function2 时,日志都会向我显示这一点。这是 Function1 的日志输出:
2021-06-10T07:58:17Z [information] ManagedIdentityCredential will use App Service managed identity
2021-06-10T07:58:17Z [information] Request URL: 'http://localhost:8081/msi/token?api-version=REDACTED&resource=REDACTED'
2021-06-10T07:58:17Z [information] Request method: 'GET'
2021-06-10T07:58:17Z [information] Request headers:
2021-06-10T07:58:17Z [information] 'secret': 'REDACTED'
2021-06-10T07:58:17Z [information] 'User-Agent': 'azsdk-python-identity/1.6.0 Python/3.7.10 (Linux-5.4.81-microsoft-standard-x86_64-with-debian-10.9)'
2021-06-10T07:58:17Z [information] No body was attached to the request
2021-06-10T07:58:17Z [information] Response status: 200
2021-06-10T07:58:17Z [information] Response headers:
2021-06-10T07:58:17Z [information] 'Date': 'Thu,10 Jun 2021 07:58:16 GMT'
2021-06-10T07:58:21Z [information] Executing 'Functions.EventHubTrigger' (Reason='(null)',Id=9b5e6c36-6227-45b1-9bd0-151f22aac147)
2021-06-10T07:58:21Z [information] Trigger Details: PartionId: 0,Offset: 51570324760-51570324760,EnqueueTimeUtc: 2021-06-10T07:58:21.3150000Z-2021-06-10T07:58:21.3150000Z,SequenceNumber: 107798-107798,Count: 1
它将发送到 localhost,所以我应该将 URL 更改为发送到 localhost 的 URL 吗? 虽然我收到 200 状态码响应。 Function2 上的登录没有显示我成功处理了任何请求。它实际上是空的。 当我向 Function2 发出手动请求时,我可以看到这样的日志:
2021-06-10T07:49:15Z [information] Python HTTP trigger function processed a request.
2021-06-10T07:49:15Z [information] The request body contained name & number
2021-06-10T07:49:17Z [information] Response status: 200
编辑 (14-6-2021): 我已经从为 Function2 使用 HTTP 触发函数转移到它被 eventhub 触发。但是,在我尝试浏览我能找到的任何博客/论坛 2 天后,问题仍然存在。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。