I'm aiming to get some Python 3 code running as an Azure Function, but I can't get Python 3 to work (I realize python support in Azure Functions is still experimental).
Here's what I've tried.
Create a new Function App - I've given it a name, and left everything else as default.
Created a Python HttpTrigger function, with the following code:
import sys import os response = open(os.environ['res'], 'w') response.write(sys.version) response.close()
Running this function gives an output of "2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]"
as expected, because 2.7.8 is the default version of python that is installed in the Azure Functions environment.
- I then uploaded the embeddable version of python 3.6.1 to d:\site\tools using Kudu, as described in this Azure wiki page
When I run the function again, I get the output "3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]"
- so all is good there.
However, if I restart the function app (or just leave it alone for a while so it gets shut down) then everything breaks. Running the function gives:
{
"id": "dd7c4462-0d73-49e0-8779-67b15a9bba82",
"requestId": "ff553805-501d-4ea6-93f6-7bd6fa445a37",
"statusCode": 500,
"errorCode": 0,
"message": "Exception while executing function: Functions.HttpTriggerPython31 -> "
}
The logs show:
2017-11-09T17:37:04.988 Function started (Id=941e5bef-e5e0-4604-8533-dd2a5fcaddf0)
2017-11-09T17:37:05.348 Exception while executing function: Functions.HttpTriggerPython31. Microsoft.Azure.WebJobs.Script: .
2017-11-09T17:37:05.364 Function completed (Failure, Id=941e5bef-e5e0-4604-8533-dd2a5fcaddf0, Duration=363ms)
If I delete the python files from d:\site\tools, then then function starts working again, but runs with v2.7.8
However, I can get python 3.x to run from the Kudu console:
D:\home\site\tools>python -c "import sys;print(sys.version)"
3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)]
Does anyone else have Python 3 successfully running in Azure Functions? What do I need to do to get it working?