使用Visual Studio在Azure上部署python flask项目 [英] deploying python flask project on azure using visual Studio

查看:103
本文介绍了使用Visual Studio在Azure上部署python flask项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将Py项目部署到Azure时遇到了一些麻烦。
我得到的消息是
该页面无法显示,因为发生了内部服务器错误。



我知道这是配置错误在项目中。
我的web.config文件具有以下内容。



Python已安装在Azure Web服务的D中,并且在运行本地计算机
的C中Py2.7



应用名称为白板



本地主机上的端口5965 ...



我在做什么错? MS文档没有帮助

 < configuration> 
< appSettings>
<添加键= WSGI_HANDLER value = whiteboard.app />
< add key = PYTHONPATH value = D:\home\site\wwwroot />
<添加密钥= WSGI_LOG value = D:\home\LogFiles\wfastcgi.log />
< / appSettings>
< system.webServer>
< handlers>
< add name = PythonHandler path = *动词= * modules = FastCgiModule scriptProcessor = D:\home\Python27\python.exe | D:\home\ \Python27\wfastcgi.py
resourceType = Unspecified requireAccess = Script />
< / handlers>
< httpPlatform processPath = C:\Python27\python.exe
arguments = F:\FYP-Whiteboard\Whiteboard\whiteboard\runserver.py%HTTP_PLATFORM_PORT%5
stdoutLogEnabled = true
stdoutLogFile = F:\FYP-Whiteboard\Whiteboard\whiteboard\LogFiles\python.log
startupTimeLimit = 60
processesPerApplication = 16>
< environmentVariables>
< environmentVariable name = SERVER_PORT value = 5965 />
< environmentVariable name = PYTHONPATH value = D:\home\site\wwwroot />
< environmentVariable name = PORT value =%HTTP_PLATFORM_PORT% />
< / environmentVariables>
< / httpPlatform>
< /system.webServer>
< / configuration>


解决方案

根据我的经验,您的问题是由软件包引起的 web.config 中丢失或路由错误。(或者您可以在 wfastcgi.log 中找到日志)我确实测试成功,请参考我的工作步骤:





第2步:发布您的烧瓶项目,并添加 web.config



web.config:

 <?xml version = 1.0 encoding = utf-8?> 
< configuration>
< appSettings>
<添加密钥= WSGI_HANDLER value =<您的项目名称> .app />
< add key = PYTHONPATH value = D:\home\site\wwwroot />
<添加密钥= WSGI_LOG value = D:\home\LogFiles\wfastcgi.log />
< / appSettings>
< system.webServer>
< handlers>
< add name = PythonHandler path = * verb = * modules = FastCgiModule scriptProcessor = D:\home\Python364x64\python.exe | D:\home\ \Python364x64\wfastcgi.py resourceType = Unspecified requireAccess = Script />
< / handlers>
< /system.webServer>
< / configuration>

第3步:切换到Kudu CMD并命令 cd Python361x64 touch get-pip.py 并复制网址 https://bootstrap.pypa.io/get-pip的内容.py 通过编辑按钮插入 get-pip.py ,然后运行 python get-pip.py 安装pip工具。





第4步:安装所需的任何软件包通过 python -m pip安装Flask





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


I am having some trouble getting my Py project to be deployed on Azure. The message I get is "The page cannot be displayed because an internal server error has occurred."

Which I know is a config error in the project. My web.config file has the below.

Python is installed in D in my azure web service and in C in my local machine running Py2.7

Appname is whiteboard

port 5965 on local host...

What am I doing wrong?? MS documentation did not help

<configuration>
    <appSettings>
    <add key="WSGI_HANDLER" value="whiteboard.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\Python27\python.exe|D:\home\Python27\wfastcgi.py"
        resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
    <httpPlatform processPath="C:\Python27\python.exe"
    arguments="F:\FYP-Whiteboard\Whiteboard\whiteboard\runserver.py %HTTP_PLATFORM_PORT%5"
    stdoutLogEnabled="true"
    stdoutLogFile="F:\FYP-Whiteboard\Whiteboard\whiteboard\LogFiles\python.log"
    startupTimeLimit="60"
    processesPerApplication="16">
    <environmentVariables>
        <environmentVariable name="SERVER_PORT" value="5965" />
        <environmentVariable name="PYTHONPATH" value="D:\home\site\wwwroot" />
        <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
    </environmentVariables>
    </httpPlatform>
    </system.webServer>
    </configuration>

解决方案

Per my experience, your issue is resulted from the package missing or route error in web.config.(Or you could find log in wfastcgi.log) I did test successfully, please refer to my working steps:

As you found in the Managing Python on Azure App Service , Azure App Service provide you with a site extension. You could install packages on KUDU console.

Step 1 : Create azure web app and add Extensions(here is Python 3.6.4 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\Python364x64\python.exe|D:\home\Python364x64\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 any packages you need via python -m pip install Flask

Hope it helps you. Any concern ,please let me know.

这篇关于使用Visual Studio在Azure上部署python flask项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆