Reputation: 7238
I have a Flask
based python web app which is running fine on azure. I have made some changes and added a input.json
file which contains some project configuration. I have below files in the project root directory:
app.py -> Main python file
input.json -> Input configuration file used by app.py
requirements.txt -> This file contains python packages used by project
web.config -> Azure web config file
Below is the content of web.config
file
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="app.wsgi_app"/>
<add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
</appSettings>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python364x64\python.exe|D:\home\Python364x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
</system.webServer>
</configuration>
This is all working fine on my local machine. But when I deployed this on azure, API was not running. I opened the kudu console and checked the logs of wfastcgi.log
, it was showing error:
No such file or directory: 'D:\\home\\python364x64\\input.json'
The problem is input.json
is located inside D:\home\site\wwwroot>
but it is automatically picking up the wrong path and thus failing the code.
1. Why it is looking for input.json
file in wrong path.?
2. How can I mention the correct path for input.json
file.?
3. If in future, I'll add more files, where should I correctly mention path of all the files. Do we have to mention this in web.config
file.?
Thanks.!
Upvotes: 0
Views: 781
Reputation: 72171
pretty sure you need to use relative path, something like this:
os.path.join(os.path.dirname( __file__ ), 'input.json')
so you will get path in the same directory your python file is located. And this is not related to web.config. your python file attempts to load this file (this is my assumption). hence its looking for it in the path relative to the interpreter, not your python file.
Upvotes: 2