1

I am trying to host my python api on azure web app. It is a Flaks based application and having a demo flask code . I have created resource group and setup everything. But when accessing the url it shows

enter image description here

although I can see from the deployment options, it has successfully deployed my bitbucket project. I have selected python3.4 version in the application settings. I have tried adding the latest python extension but only 3.6version is available. I have added the python3.6 extension but it still only show python3.4 in application settings.

I do not know how can I resolve this issue. Please help. Thanks.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
S Andrew
  • 5,592
  • 27
  • 115
  • 237
  • Did you try manually to make sure the deployment is successful into Azure, through `Kudo (Advance Tools/App Service Editor )` – Jayendran Aug 19 '18 at 10:18
  • Possible duplicate of [Azure Flask Deployment - WSGI Interface](https://stackoverflow.com/questions/32518358/azure-flask-deployment-wsgi-interface) – Arnav Chawla Aug 20 '18 at 21:56

2 Answers2

2

S Andrew.

web.config file is essential in the deployment of your web App.You could create the web.config file on the KUDU url.

You could navigate to KUDU via below two way:

1.Find the button on the portal.

enter image description here

2.access url directly: https://.scm.azurewebsites.net/

On the KUDU,you could see your app structure in the path: D:\home\site\wwwroot,you need to create web.config file here.

enter image description here

Also,you could see your python extension in the path:D:\home\, if you want to use extension environment, you need to configure the correct path in web.config.

enter image description here

Please see my sample web.config file.Related to web.config, you could refer to this official doc.

<configuration>
  <appSettings>
    <add key="WSGI_HANDLER" value="<your app name>.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\Python361x64\python.exe|D:\home\Python361x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
  </system.webServer>
</configuration>

More details about python app deployment on the azure,please see my previous cases,you will find the answer.

1.Failed to Deploy Flask to Azure

2.deploying python flask project on azure using visual Studio

Hope it helps you.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • Thank you very much. I will definitely try this and will get back to you. – S Andrew Aug 22 '18 at 04:08
  • @SAndrew Sure,waiting for you reply. – Jay Gong Aug 22 '18 at 04:09
  • @Yes. I created the `web.config` file but python was not in `D:\home`, it was in D:\ so I used this path in web.config. Also you mentioned that we need to write our app name in value for `WSGI_HANDLER` in `web.config` but python file has extension `.py` not `.app`.? Its still not working. – S Andrew Aug 24 '18 at 07:15
  • @SAndrew Do you have time to join this chat :https://chat.stackoverflow.com/rooms/178670/pythonwebapp – Jay Gong Aug 24 '18 at 09:13
  • Yes. I am in the chat now. Lets continue there. – S Andrew Aug 24 '18 at 09:14
  • Just want to let you know that it worked perfectly fine after creating the project using visual studio. Thanks for all your help and support. – S Andrew Aug 24 '18 at 16:12
  • @SAndrew Great ! – Jay Gong Aug 24 '18 at 16:34
  • Hi. Just wanted to know one thing, I have `input.json` which my main python file is using to get some input configurations. In the kudu console, I can see it inside `D:\home\site\wwwroot>` but when I check logs of `wfastcgi.log`, it says `No such file or directory: 'D:\\home\\python364x64\\devconfig.json'`. Why it is looking the file inside `D:\\home\\python354x64`. Where do I mention the correct path of the file. Thanks – S Andrew Aug 26 '18 at 12:44
  • https://stackoverflow.com/questions/52026530/where-to-mention-path-of-files-in-azure-flask-based-python-app – S Andrew Aug 26 '18 at 13:06
  • @JayGong Still not working. getting error " An error has occurred during web site deployment." Unsupported runtime python 3.6 – Ragavan Rajan Jan 10 '19 at 01:59
  • @RagavanRajan Sorry for late,which case? – Jay Gong Jan 10 '19 at 02:05
  • @JayGong added web.config in wwwroot folder. Getting the above error – Ragavan Rajan Jan 10 '19 at 02:11
1

You have to make a webconfig file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <add key="WSGI_HANDLER" value="main.app"/>
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x86\python.exe|D:\home\Python364x86\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
  </system.webServer>
</configuration>

Make sure to change the value of main.app to whatever your file name is and to change the path for python to your path. This solved the issue for me.

  • Hi, where did you get this weconfig file. Can you please share link. Or can you please add some explanation like why you have set `PYTHONAPTH` value to `D:\home\site\wwwroot"/`. – S Andrew Aug 20 '18 at 11:54
  • yes pls tell why did you set the PYTHON path to`D:\home\site\wwwroot` pls – Ragavan Rajan Jan 10 '19 at 01:55