ValueError: "hostingstart.app" could not be imported

ValueError: "hostingstart.app" could not be imported

正在尝试为 flask python 创建 azure python 网络应用程序 python,但出现以下错误

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 找不到错误

文件夹结构:

WWWroot
 - hostingstart.py
 - view.py
 - web.config

hostingstart.py

from flask import Flask
app = Flask(__name__)

import view
wsgi_app = app.wsgi_app

Web.Config

<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 应用程序自带的版本。

第 1 步:添加扩展(这里是 Python 3.6.1 x64)

第 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>.

如果您想使用额外的 python 包,请继续。

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

第 4 步:通过 python -m pip install pyodbc

安装您需要的任何软件包