gpt4 book ai didi

Azure python 函数执行函数 : Functions. HttpExample 时出现异常。 System.Private.CoreLib:结果:失败

转载 作者:行者123 更新时间:2023-12-05 02:38:25 25 4
gpt4 key购买 nike

我有一个 azure 的Python函数。我正在尝试通过我的函数将数据发布到 API 端点。下面是我的相同代码,

import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
req_body = req.get_json()
url = "https://example.com/msgs"
payload= req.get_body()
headers = {
'Authorization': 'mytoken ',
}
response = func.HttpRequest(method="POST", url=url, headers=headers, body=payload,params=None,route_params=None)
return func.HttpResponse("", response)
except :
func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)

每次调用函数时,都会出现以下错误,

Executed 'Functions.HttpExample' (Failed, Id=bc8a184c-7b20-4946-a92c-ed2afad66e56, Duration=17ms)
[2021-10-15T20:14:11.494Z] System.Private.CoreLib: Exception while executing function: Functions.HttpExample. System.Private.CoreLib: Result: Failure
Exception: TypeError: unable to encode outgoing TypedData: unsupported type "<class 'azure.functions.http.HttpResponseConverter'>" for Python type "NoneType"
Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.9\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 427, in _handle__invocation_request
return_value = bindings.to_outgoing_proto(
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.9\WINDOWS\X64\azure_functions_worker\bindings\meta.py", line 116, in to_outgoing_proto
datum = get_datum(binding, obj, pytype)
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.9\WINDOWS\X64\azure_functions_worker\bindings\meta.py", line 107, in get_datum
raise TypeError(

谁能帮我解决这个问题吗?或者告诉我一种从 azure python 函数进行 POST 调用的方法?

谢谢,廷图

最佳答案

我有同样的错误,但我的问题不同。我注释掉了一段代码,其中包括以下行:

return func.HttpResponse(“Request processed successfully.”, status_code=200)

注释掉这一行意味着该函数将在没有 HTTP 响应的情况下结束,因此返回 None。这就是我的错误中“None”类型的来源。我希望这对其他人有帮助!

关于Azure python 函数执行函数 : Functions. HttpExample 时出现异常。 System.Private.CoreLib:结果:失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69590192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com