python - ValueError:无法导入“hostingstart.app”
问题描述
尝试为烧瓶 python 创建 azure python web 应用程序,但出现以下错误
Error occurred while reading WSGI handler:
Traceback (most recent call last): File "D:\Python34\Scripts\wfastcgi.py", line 711, in main
env, handler = read_wsgi_handler(response.physical_path) File "D:\Python34\Scripts\wfastcgi.py", line 568, in read_wsgi_handler
return env, get_wsgi_handler(handler_name) File "D:\Python34\Scripts\wfastcgi.py", line 551, in get_wsgi_handler
raise ValueError('"%s" could not be imported' % handler_name) ValueError: "hostingstart.app" could not be imported
标准输出:
标准错误:
我尝试升级 wfastcgi,之后我将脚本位置更改为新的 wfastcgi,它正在抛出脚本处理程序 scriptProcessor could not be found in error
文件夹结构:
WWWroot
- hostingstart.py
- view.py
- web.config
托管启动.py
from flask import Flask
app = Flask(__name__)
import view
wsgi_app = app.wsgi_app
网络配置
<configuration> <appSettings>
<add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
<add key="WSGI_HANDLER" value="hostingstart.app"/>
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/> </appSettings> <system.webServer>
<httpErrors errorMode="Detailed"></httpErrors>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="FastCgiModule"
scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py"
resourceType="Unspecified" requireAccess="Script" />
</handlers> </system.webServer> </configuration>
解决方案
您可以尝试python extension version
按照以下步骤安装,而不是使用 azure web app 自带版本。
第 1 步:添加扩展(这里是 Python 3.6.1 x64)
第 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>
如果部署成功,您可以在KUDU
路径中看到以下结构:D:\home\site\wwwroot>
.
如果你想使用额外的python包,请继续。
第三步:切换到 Kudu CMD 和命令cd Python361x64
,touch get-pip.py
并将 url 的内容复制https://bootstrap.pypa.io/get-pip.py
到get-pip.py
via Edit 按钮,然后运行python get-pip.py
安装 pip 工具。
第 4 步:通过以下方式安装您需要的任何软件包python -m pip install pyodbc
推荐阅读
- c++ - CPP 将类写入/读取到二进制文件中
- konvajs - 缩放到 konva.js 中的特定形状
- windows - 适用于 Windows 的全新 Flutter 应用的 CPU 使用率较高
- sql - 分区组的SQL运行余额计算
- kubernetes - Istio 虚拟服务中的查询参数匹配
- anylogic - 安排操作员休息时间
- delphi - 如何解密此 2D 加密?
- cookies - 保存会话 cookie 以在 Chrome 中显示弹出窗口
- python - 使用 Django 发送 S/MIME 签名邮件
- suitecrm - 当收到的邮件进入 suiteCRM 时,我们如何为自动创建 CASE 提供条件