gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:09:17 25 4
gpt4 key购买 nike

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

HTTP Error 500.0 - Internal Server Error scriptProcessor could not be found in  application configurationDetailed Error Information:Module     FastCgiModuleNotification       ExecuteRequestHandlerHandler    PythonHandlerError Code     0x80070585Requested URL      http://OcvCluster-int__b155:80/handler.fcgi/Physical Path      D:\home\site\wwwroot\handler.fcgi\Logon Method       AnonymousLogon User     AnonymousRequest 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://learn.microsoft.com/en-us/visualstudio/python/managing-python-on-azure-app-servicehttps://learn.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>

谢谢,〜约翰

最佳答案

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

尽管应用服务默认在服务器的根文件夹中安装了 Python 2.7 和 Python 3.4,但您无法在这些环境中自定义或安装包。

enter image description here

因此,Azure 应用服务建议您现在依赖站点扩展

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

但是,这现在不适用于网站扩展。您可以在 KUDU 控制台 上安装软件包。请引用我之前的步骤。

第 1 步:创建 Azure Web 应用程序并添加扩展(此处为 Python 3.6.1 x64)

enter image description here

第 2 步:发布您的 flask 项目并添加 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并复制url内容https://通过编辑按钮将 bootstrap.pypa.io/get-pip.py 复制到 get-pip.py 中,然后运行 ​​python get-pip.py 进行安装点工具。

enter image description here

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

enter image description here

此外,我注意到 web.config 中的 PYTHONPATH 配置不包含应用程序的根路径,即 D:\home\site\wwwrootPYTHONPATH 的值可以自由扩展,但必须包含应用程序的根目录。

并且您需要检查映射到 scriptProcessor 的路径中的 Python Interpreter 是否存在。

希望对您有帮助。如有任何疑问,请告诉我。

关于将项目从 VS 2015 升级到 2017 后,Azure 上的 Python Flask 应用程序损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48387711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com