Azure python函数在执行函数时出现异常:Functions.HttpExample.System.Privat



我有一个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 FilesMicrosoftAzure Functions Core Toolsworkerspython3.9WINDOWSX64azure_functions_workerdispatcher.py", line 427, in _handle__invocation_request
return_value = bindings.to_outgoing_proto(
File "C:Program FilesMicrosoftAzure Functions Core Toolsworkerspython3.9WINDOWSX64azure_functions_workerbindingsmeta.py", line 116, in to_outgoing_proto
datum = get_datum(binding, obj, pytype)
File "C:Program FilesMicrosoftAzure Functions Core Toolsworkerspython3.9WINDOWSX64azure_functions_workerbindingsmeta.py", line 107, in get_datum
raise TypeError(

谁能帮我解决这个问题?或者告诉我如何从azure python函数进行POST调用?

谢谢,Tintu

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

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

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

我也遇到了同样的问题!

我得到这个错误:

Exception while executing function: Functions.DouMonitorHttpStart <--- Result: Failure Exception: TypeError: unable to encode outgoing TypedData: unsupported type "<class 'azure.functions.http.HttpResponseConverter'>" for Python type "dict" Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 427, in _handle__invocation_request return_value = bindings.to_outgoing_proto( File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/bindings/meta.py", line 116, in to_outgoing_proto datum = get_datum(binding, obj, pytype) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/bindings/meta.py", line 107, in get_datum raise TypeError(

但是在重新运行之后,它最终成功了。

这种情况发生在我身上,我有一个try块和一个finally块,没有except或else块。我添加了except和else块,它工作得很好。

相关内容

最新更新