首页 > 解决方案 > 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>

标签: pythonazureflaskfastcgiazure-web-app-service

解决方案


您可以尝试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 Python361x64touch get-pip.py并将 url 的内容复制https://bootstrap.pypa.io/get-pip.pyget-pip.pyvia Edit 按钮,然后运行python get-pip.py安装 pip 工具。

在此处输入图像描述

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

在此处输入图像描述


推荐阅读