简体   繁体   中英

How to run python3.7 based flask web api on azure

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

在此输入图像描述

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.

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.

在此输入图像描述

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.

在此输入图像描述

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 .

在此输入图像描述

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM