I'm trying to make the hello world example work for python via azure functions. The basic function tries to retrieve a name as input through the url and then respond "Hello Name". It turns out that the example-template which is available through the azure portal does not work out of the box. The basic example looks like this:
import os
import json
postreqdata = json.loads(open(os.environ['req']).read())
response = open(os.environ['res'], 'w')
response.write("hello world from "+postreqdata['name'])
response.close()
The two environment variables req and res are paths to temporary files storing input and output from the function as json. The idea is that input passed through the url should be available in the dictionary returned by json.loads(). The only dilemma is that the file located at os.environ['req'] is empty no matter what I do.
os.path.isfile(os.environ['req'])
# Returns True so the file is located at:
# D:\local\Temp\Functions\Binding\79fcec12-baf3-470e-87c3-113f64ffcef0\req
# during the execution
I tried the Hello world JavaScript example as well which works directly out of the box on azure-functions. My python script works fine when executing in within the azure-portal, but fails when triggering it from a web browser.
The function runs on Python 2.7.13 with extension &name=MyName to the https adress.
I believe the bug is not in the script itself, but hidden in the backbone somewhere. Anyone tried the same?