无法将Flask部署到Azu

2024-05-16 04:44:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将pythonflask部署到azure,但无法通过。我在Azure上创建一个api服务

这是我的url,它与python 3https://textclassifier.azurewebsites.net/一起使用

然后我在visual studio上创建了一个默认的flask项目,在不更改任何代码的情况下,我直接单击publish。选择了我从门户网站创建的应用程序服务,发布在VS输出中成功显示:

Adding file (TextClassifier\TestFlask__init__.py). Adding ACLs for path (TextClassifier) Adding ACLs for path (TextClassifier) Publish Succeeded. Web App was published successfully http://textclassifier.azurewebsites.net/ ========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ========== ========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

但是,当我访问urlhttps://textclassifier.azurewebsites.net/home时,浏览器显示:“您要查找的资源已被删除、名称已更改或暂时不可用”。在

我检查了/home是否路由到控制器

谁能帮帮我,我已经被困了好几天了。在


Tags: pathhomefornet部署publishsucceededfailed
1条回答
网友
1楼 · 发布于 2024-05-16 04:44:43

根据我的经验,你的问题是由azure应用程序python环境造成的。请参考我的工作步骤,看看错误是否仍然出现。在

正如您在Managing Python on Azure App Service中发现的,Azure应用程序服务为您提供了一个site extension。您可以在KUDU console上安装包。在

步骤1:创建azure web应用程序并添加扩展(这里是Python3.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命令和命令cd Python361x64touch get-pip.py,通过编辑按钮将url https://bootstrap.pypa.io/get-pip.py复制到get-pip.py中,然后运行python get-pip.py来安装pip工具。在

enter image description here

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

enter image description here

希望对你有帮助。有什么问题,请告诉我。在

相关问题 更多 >