Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using python 3.6 on azure app services - not working despite it is installed as extension

I've got a challenge with deploying Django app (wagtail to be precise) to Azure Web Services using external Git repo (Bitbucket). I want to use Python 3.6.1, therefore I followed instructions at Managing Python on Azure App Service manual

  • I have python 3.6.1 extension installed and in place
  • I created web.config file in root directory of my app (I checked and it is uploaded to the server)

However, deploy fails with message

Detecting Python runtime from runtime.txt
Unsupported runtime: python-3.6.1

Supported runtime values are:
python-2.7
python-3.4
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\66.61008.3066\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

My web.config file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <!-- Django apps only -->
    <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()"/>
    <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>

Paths are ok, below is ls from Kudu console

D:\home\python361x64>ls
DLLs
Lib
Scripts
__pycache__
python.exe
python3.dll
python36.dll
pythonw.exe
sitecustomize.py
vcruntime140.dll
wfastcgi.py

It looks like the deployment process is not taking into account the web.config file that I have, or the python version that I've installed via extensions is not visible.

Could you please tell me where the possible issue could be?

Best regards,
Konrad

like image 679
Konrad Avatar asked Dec 10 '22 09:12

Konrad


1 Answers

After a couple of hours of fighting, I finally managed to run this bastard as expected ;)

Thanks, @Jay Gong for your input as going step by step with this tutorial showed me a couple of things.

  1. runtime.txt file, which I had in the root folder, was the first issue. As 3.6 version of python is installed via extensions, in fact, deployment process does not now that this v. exists (it "knows" only 2.7 and 3.4). So the first step was to get rid of this file.
  2. When runtime.txt had been removed, deployment process has been using python 3.4 and was failing on installation one of the dependencies from requirements.txt file (probably because of the older version of python). So the next step was to add .skipPythonDeployment, to avoid automatic installation of requirements and install those manually by kudu console. In folder with our python env (in my case D:\home\python361x64) following command was launched
    python.exe -m pip install --upgrade -r D:\home\site\wwwroot\requirements.txt
    All dependencies were installed correctly.

  3. After deploy, launching an app in a web browser showed message The page cannot be displayed because an internal server error has occurred.. Next step was to gather more info about the issue, so I have added a few new lines in web.config file:

    ....
    <system.webServer>
    ....
        <httpErrors errorMode="Detailed"></httpErrors>
    </system.webServer>
    <system.web>
        ....
         <customErrors mode="Off" />
    </system.web>
    

    Thanks to that, I was able to check what is causing the issue. In my case, it was a WSGI_HANDLER value in web.config. I set it to a correct value (for wagtail it was <app_name>.wsgi.application and then it started working.

Thank you guys for all your support.

like image 64
Konrad Avatar answered May 15 '23 05:05

Konrad