I have Implemented an Azure Function in Python which only works on Azure Linux servers. Using Visual Studio Code I managed to run the functions locally and performed the testing with postman the requests worked successfully. I have also deployed the functions to Azure using Visual Studio Code and again tested the public REST API host with Postman and it worked.
The problem was calling this API through my web application which returned CORS error. I know this is normal because I didn't set allow all (*) property in the CORS through Azure panel. Basically, because the CORS is blocked:
When I click I get the following warning:
This feature is not supported for Linux apps on a Consumption plan
I have tried adding the headers inside my python function like:
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS"
}
And then in the response:
return func.HttpResponse(f"{result}",headers=headers)
But still getting the CORS error.
Try enabling CORS with the Azure CLI,
az functionapp cors add --allowed-origins
[--ids]
[--name]
[--resource-group]
[--slot]
[--subscription]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With