We have a Python flask application running as an App Service in Azure. We recently upgraded our solutions to VS 2017. This changed some of the configuration files in the python project and now when we publish, we get:
HTTP Error 500.0 - Internal Server Error scriptProcessor could not be found in application configuration Detailed Error Information: Module FastCgiModule Notification ExecuteRequestHandler Handler PythonHandler Error Code 0x80070585 Requested URL http://OcvCluster-int__b155:80/handler.fcgi/ Physical Path D:\home\site\wwwroot\handler.fcgi\ Logon Method Anonymous Logon User Anonymous Request Tracing Directory D:\home\LogFiles
If I go back to an old (pre-upgrade) version I can publish from 2015. I can’t, however, open the latest master in 2015, so I am unable to publish changes we need in our service.
I have spent a full day going through articles like:
https://docs.microsoft.com/en-us/visualstudio/python/managing-python-on-azure-app-service
https://docs.microsoft.com/en-us/visualstudio/python/publishing-to-azure
Trying many things with reg to updating my web.config.
Is there any information on what the upgrade path should be here? We are broken. Things that confuse me:
• Tutorials on publishing Flask apps to VS state that you need to install Python as an extension on the App Service. Is that new? We have not been doing that previously.
• We have a bunch of custom libraries in our env folder. In VS2015, those are uploaded as part of the publish process. When I publish from VS 2017 I don’t see that happening (though they are still there from previous publishes)
• Some forum posts have talked about having to point to the interpreter in the application.config. Our app does not have an application.config.
Here is my web.config (with the comments indicating where I have been experimenting).
<?xml version="1.0"?>
<!-- Generated web.config for Microsoft Azure. Remove this comment to prevent
modifications being overwritten when publishing the project.
-->
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<appSettings>
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="redacted.app" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env3\Scripts\python.exe" />
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()" />
<!--add key="WSGI_HANDLER" value="redacted.app" />-->
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
<!--<add key="PYTHONPATH" value="%ROOTDIR%;%ROOTDIR%\redacted;%ROOTDIR%\redacted\Clusterer\" />-->
<add key="PYTHONPATH" value="D:\home; D:\home\site;D:\home\site\redacted;D:\home\site\redacted\Clusterer\" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed"></httpErrors>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<!--<add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="%INTERPRETERPATH%|%WFASTCGIPATH%" resourceType="Unspecified" requireAccess="Script" />-->
<add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python354x64\python.exe|D:\home\python354x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<httpPlatform processPath="D:\home\python354x64\python.exe"
arguments="D:\home\site\wwwroot\runserver.py"
stdoutLogEnabled="true"
stdoutLogFile="D:\home\LogFiles\python.log"
startupTimeLimit="60"
processesPerApplication="16">
<environmentVariables>
<environmentVariable name="SERVER_PORT" value="%HTTP_PLATFORM_PORT%" />
</environmentVariables>
</httpPlatform>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<match url="^/static/.*" ignoreCase="true" />
<action type="Rewrite" url="^/redacted/static/.*" appendQueryString="true" />
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks, ~john
As you found in the Managing Python on Azure App Service :
Although App Service by default has Python 2.7 and Python 3.4 installed in root folders on the server, you cannot customize or install packages in these environments.
So, Azure App Service recommands you rely on a site extension
now.
As far as I know, we could list the version of python packages which program relies on in the requirements.txt
file. Those packages will be downloaded into the env
folder when the project is deployed to Azure.
However , this does not apply to site extensions
now. You could install packages on KUDU console
. Please refer to the steps I worked before.
Step 1 : Create azure web app and add Extensions(here is Python 3.6.1 x64)
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.
Step 4 : Install pyodbc package or any packages you need via python -m pip install pyodbc
In addition, I notice that your PYTHONPATH
configuration in the web.config does not include the root path of your app which is D:\home\site\wwwroot
. The value for PYTHONPATH
may be freely extended but must include the root of your app.
And you need to check if the Python Interpreter in the path which mapped to scriptProcessor exists.
Hope it helps you. Any concern ,please let me know.
User contributions licensed under CC BY-SA 3.0