找不到Azure烧瓶路由

时间:2018-07-02 20:34:42

标签: python azure flask deployment

我正在使用Visual Studio创建一个空白的Flask应用程序。当我在本地运行应用程序时,我得到了预期的“ hello world”。当我发布到Azure App Service时,会得到一个我没有制作的漂亮的丑陋蓝色主页。该代码在我的项目中不存在,至少在Visual Studio解决方案资源管理器中可以看到。如果我尝试与<my account name>.azurewebsites.net/test协商,则会收到404错误。有什么建议吗?

enter image description here

app.py:

from flask import Flask
app = Flask(__name__)

# Make the WSGI interface available at the top level so wfastcgi can get it.
wsgi_app = app.wsgi_app

@app.route('/test')
@app.route('/')
def hello():
    """Renders a sample page."""
    return "Hello World!"

if __name__ == '__main__':
    import os
    HOST = os.environ.get('SERVER_HOST', 'localhost')
    try:
        PORT = int(os.environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555
    app.run(HOST, PORT)

网络deploy.pubxml:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <ResourceId>/subscriptions/78439574-998e-4216-b54c-40fa45d65ca5/resourceGroups/Default-SQL-EastUS/providers/Microsoft.Web/sites/FlaskWebProject220180702122411</ResourceId>
    <ResourceGroup>Default-SQL-EastUS</ResourceGroup>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://flaskwebproject220180702122411.azurewebsites.net</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <MSDeployServiceURL>flaskwebproject220180702122411.scm.azurewebsites.net:443</MSDeployServiceURL>
    <DeployIisAppPath>FlaskWebProject220180702122411</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <UserName>$FlaskWebProject220180702122411</UserName>
    <_SavePWD>True</_SavePWD>
    <_DestinationType>AzureWebSite</_DestinationType>
  </PropertyGroup>
</Project>

更新:

我遵循了杰伊列出的步骤。我现在收到“由于发生内部服务器错误而无法显示该页面。”。我在应用程序设置中添加了一个日志文件,但是它没有出现。

enter image description here

enter image description here

UPDAtE 2

我注意到在我的web.config文件中,版本是不同的,所以我对其进行了更新。这样就可以创建logs.txt。

  <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python364x64\python.exe|D:\home\Python364x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>

我仍然遇到500错误。

logs.txt: enter image description here

1 个答案:

答案 0 :(得分:2)

请参考我的工作步骤,看看错误是否仍然出现。

第1步:创建一个Azure Web应用并添加扩展程序(这里是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>

如果部署成功,您将在KUDU路径中看到以下结构:D:\home\site\wwwroot>

enter image description here

如果要使用其他python软件包,请继续。

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

enter image description here

第4步:通过python get-pip.py

安装所需的任何软件包

enter image description here

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


更新

在我的步骤中,复制python -m pip install pyodbc中的内容以安装pip。它可以识别系统python版本,安装相应的python软件包。

enter image description here

因此,您只需要运行命令https://bootstrap.pypa.io/get-pip.py来安装python -m pip install newspaper3k

enter image description here