在将项目从VS 2015升级到2017之后,Azure上的Python Flask应用程序已损坏

时间:2018-01-22 18:06:23

标签: python azure flask visual-studio-2017

我们有一个在Azure中作为App Service运行的Python烧瓶应用程序。我们最近将我们的解决方案升级到VS 2017.这改变了python项目中的一些配置文件,现在当我们发布时,我们得到:

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

如果我回到旧的(升级前)版本,我可以从2015年发布。但是,我不能在2015年开设最新的大师,因此我无法在我们的服务中发布我们需要的更改。 / p>

我花了一整天时间阅读以下文章: 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

尝试使用reg来更新我的web.config。

是否有关于升级路径应该在哪里的信息?我们坏了。困扰我的事情:

•将Flask应用程序发布到VS的教程说明您需要在App Service上安装Python作为扩展。这是新的吗?我们之前没有这样做过 •我们的env文件夹中有一堆自定义库。在VS2015中,这些是作为发布过程的一部分上载的。当我从VS 2017发布时,我没有看到这种情况发生(尽管它们仍然存在于以前的出版物中) •一些论坛帖子已经谈到必须指向application.config中的解释器。我们的应用程序没有application.config。

这是我的web.config(注释表明我一直在尝试的地方)。

                <?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>

谢谢, 〜约翰

1 个答案:

答案 0 :(得分:0)

正如您在Managing Python on Azure App Service中找到的那样:

虽然App Service默认情况下在服务器的根文件夹中安装了Python 2.7和Python 3.4,但您无法在这些环境中自定义或安装软件包。

enter image description here

因此,Azure App Service建议您现在依赖site extension

据我所知,我们可以列出程序在requirements.txt文件中依赖的python包的版本。将项目部署到Azure时,这些包将下载到env文件夹中。

但是,现在这不适用于site extensions。您可以在KUDU console上安装软件包。请参考我之前工作的步骤。

步骤1:创建azure web app并添加Extensions(此处为Python 3.6.1 x64)

enter image description here

第2步:发布您的flask项目并添加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>

步骤3:切换到Kudu CMD并命令cd Python361x64touch get-pip.py并通过编辑按钮将网址https://bootstrap.pypa.io/get-pip.py的内容复制到get-pip.py,然后运行{ {1}}安装pip工具。

enter image description here

步骤4:通过python -m pip install pyodbc安装pyodbc软件包或任何所需的软件包

enter image description here

此外,我注意到web.config中的python get-pip.py配置不包含应用的根路径PYTHONPATHD:\home\site\wwwroot的值可以自由扩展,但必须包含应用的根目录。

您需要检查映射到scriptProcessor的路径中的Python解释器是否存在。

希望它对你有所帮助。如有任何疑虑,请告诉我。

相关问题