Reputation: 562
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
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
Upvotes: 4
Views: 6403
Reputation: 2370
I am posting the missing parts of Calfy answer.
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="app.wsgi_app" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\python361x64\python.exe" />
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()"/>
app.wsgi_app is actually app.py in your folder and from what i understand it must be an wsgi app not regular python app.. (i also used cherrypy mod here) this sample app is copied somewhere from internet.
import sys
import cherrypy
class Hello(object):
@cherrypy.expose
@cherrypy.tools.response_headers(headers=[('Content-Type', 'text/plain')])
def index(self):
message = """\
Hello Azure!
Python: {python_version}
CherryPy: {cherrypy_version}
More info: http://blog.cincura.net/id/233498
"""
return message.format(python_version=sys.version, cherrypy_version=cherrypy.__version__)
wsgi_app = cherrypy.Application(Hello(), '/')
if __name__ == '__main__':
from wsgiref.simple_server import make_server
httpd = make_server('', 6600, wsgi_app)
httpd.serve_forever()
Upvotes: 0
Reputation: 562
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.
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.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.
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.
Upvotes: 10
Reputation: 23782
I tried to reproduce your issue but failed.I tried to deploy my own django web app
to azure and it works.
You could refer to my steps and check if you you missed something.
Step 1: Follow the official tutorial to create your azure web app.
Step 2: Add Python extension.
Step 3: Add web.config
file and deploy your web app.
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="<your project name>.wsgi.application"/>
<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="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python361x64\python.exe|D:\home\python361x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Step 4: Install pip plugin
in your python extension environment
.
Step 5: Install django
module and other modules you want to use.
There are some similar SO threads you could refer to.
Hope it helps you.
Upvotes: 3