I'm having trouble understanding the problem here.
https://localhost:5007/api/BARCODE_API
type
parameter of the URL
This works:
import azure.functions as func
import logging
def main(req: func.HttpRequest) -> func.HttpResponse:
if req.params.get('type'):
return func.HttpResponse(
"Test SUCCESS",
status_code=200
)
else:
return func.HttpResponse(
"Test FAIL",
status_code=400
)
I can't see why this does NOT work...
import azure.functions as func
import logging
def main(req: func.HttpRequest) -> func.HttpResponse:
def check_type():
try:
if req.params.get('type'):
return func.HttpResponse(
"Test SUCCESS",
status_code=200
)
except:
return func.HttpResponse(
"Test FAIL",
status_code=400
)
check_barcode = check_type()
req.params.get('type')
to the check_type()
function, but same error..Error
Exception: TypeError: unable to encode outgoing TypedData: unsupported type "<class 'azure.functions.http.HttpResponseConverter'>" for Python type "NoneType"
I can't see why this is happening when I send https://localhost:5007/api/BARCODE_API?type=ean13
EDIT 1: Using @MohitC's recommended syntax still causes the error above.
The problem with your code is that if your if req.params.get('type'):
is evaluating to false, then no exception is raised and your function returns None
type, which is probably further causing the mentioned error.
There are couple of things you could do here,
except
part would return what you want. def check_type():
try:
if req.params.get('type'):
return func.HttpResponse(
"Test SUCCESS",
status_code=200
)
else:
return func.HttpResponse(
"Test FAIL",
status_code=400
)
except:
return func.HttpResponse(
"Test FAIL",
status_code=400
)
EDIT:
Based on architecture of your Azure API shown elegantly in Gif's, it looks like your main function must return something. You are collecting the HTTP response in check_barcode
but not returning it.
Try below code:
import azure.functions as func
import logging
def main(req: func.HttpRequest) -> func.HttpResponse:
def check_type():
try:
if req.params.get('type'):
return True
else:
return False
except:
return False
check_barcode = check_type()
if check_barcode:
return func.HttpResponse(
"Test SUCCESS",
status_code=200
)
else:
return func.HttpResponse(
"Test FAIL",
status_code=400
)