eigen
eigen

Reputation: 95

Failed to Deploy Flask to Azure

I'm trying to deploy python flask to azure but can not get it through. I create a api service on Azure

Here is the url for my api, and it serves with python 3 https://textclassifier.azurewebsites.net/

then I created a default flask project on visual studio, without changing any code, I click publish directly. Chosen the the app service I created from portal, publishing shows successfully in VS Output:

Adding file (TextClassifier\TestFlask__init__.py). Adding ACLs for path (TextClassifier) Adding ACLs for path (TextClassifier) Publish Succeeded. Web App was published successfully http://textclassifier.azurewebsites.net/ ========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ========== ========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

However, when I access url https://textclassifier.azurewebsites.net/home browers shows : " The resource you are looking for has been removed, had its name changed, or is temporarily unavailable".

I checked that /home is routed to a controller

Can anyone help me out, I have been stuck for days.

Upvotes: 2

Views: 830

Answers (1)

Jay Gong
Jay Gong

Reputation: 23792

Per my experience, your issue is resulted from the azure app python environment. Please refer to my work steps and see if the error still shows up.

As you found in the Managing Python on Azure App Service , Azure App Service provide you with a site extension. You could install packages on KUDU console.

Step 1 : Create azure web app and add Extensions(here is Python 3.6.1 x64)

enter image description here

Step 2 : Publish your flask project and add the web.config.

web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="WSGI_HANDLER" value="<Your Project 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>

Step 3: Switch to the Kudu CMD and commands cd Python361x64 and touch get-pip.py and copy the content of the url https://bootstrap.pypa.io/get-pip.py into the get-pip.py via Edit button, then run python get-pip.py to install the pip tool.

enter image description here

Step 4 : Install any packages you need via python -m pip install pyodbc

enter image description here

Hope it helps you. Any concern ,please let me know.

Upvotes: 2

Related Questions