I have a azure python function. I am trying to post data to an API endpoint through my function. Below is the code I have for the same,
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
)
Every time I invoke my function, I get below error,
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(
Can anyone help me to fix this issue? or tell me a way to make a POST call from azure python function?
Thanks, Tintu