【问题标题】:django on IIS winserver 2016 wfastcgi handler line 791IIS winserver 2016 wfastcgi 处理程序行 791 上的 django
【发布时间】:2020-06-13 13:25:57
【问题描述】:

在 windows server 2016 上安装了 python 3.8.1 ,django 3.0.3 和 wfastcgi,我得到这个错误,找不到任何修复它..

授予 IIS AppPool\DefaultAppPool 对 python 安装文件夹的读取和使用权限,但它仍然无法正常工作,不知何故处理程序无法读取它,但据我所知,配置似乎是正确的。希望您能够帮助我。感谢您的问候。

C:\inetpub\wwwroot -> web.conf

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="Python FastCGI"
                path="*"
                verb="*"
                modules="FastCgiModule"
                scriptProcessor="c:\users\administrator\python38\python.exe|c:\users\administrator\python38\lib\site-packages\wfastcgi.py"
                resourceType="Unspecified"
                requireAccess="Script" />
        </handlers>
    </system.webServer>

    <appSettings>
        <!-- Required settings --> 
        <add key="WSGI_HANDLER" value="web.wsgi.application" />
        <add key="PYTHONPATH" value="C:\inetpub\wwwroot\AddressLizenzbuch" />

        <!-- Optional settings -->

        <add key="DJANGO_SETTINGS_MODULE" value="web.settings" />

    </appSettings>
</configuration>

C:\inetpub\wwwroot\AddressLizenzbuch\web\blog\static -> web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <!-- Overrides the FastCGI handler to let IIS serve the static files -->
        <handlers>
            <clear/>
            <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        </handlers>
    </system.webServer>
</configuration>

manage.py

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'web.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

错误

Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "c:\users\administrator\python38\lib\site-packages\wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "c:\users\administrator\python38\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "c:\users\administrator\python38\lib\site-packages\wfastcgi.py", line 603, in get_wsgi_handler
    handler = getattr(handler, name)
AttributeError: module 'web' has no attribute 'wsgi'


StdOut: 

StdErr:

【问题讨论】:

  • 尝试把python文件夹放到c盘,比如c:\python38\。在安装时,您是否为所有用户设置了安装?将 iis_iusrs 和 iusr 权限设置为站点文件夹和 python 文件夹。详情请参考此链接:docs.microsoft.com/en-us/visualstudio/python/…
  • 在您的网络浏览器中(如图),您为什么要导航到 localhost/AddressLizenzbuch 而不仅仅是 localhost?我建议仔细检查您到C:\inetpub\wwwroot\AddressLizenzbuch 的路径。例如,您可以在终端上列出该路径的内容吗?我认为在 Windows CMD 终端上,命令将是 dir C:\inetpub\wwwroot\AddressLizenzbuch
  • 通常,您不会重命名外部项目目录。你会有类似C:\inetpub\wwwroot\webproject\webproject\wsgi.py

标签: python django iis windows-server-2016


【解决方案1】:

这应该很容易解决。你的 Django 项目是如下结构

C:/inetpub/wwwroot/AddressLizenzbuch/web/webweb.config

问题是额外的目录AddressLizenzbuch删除它。

您的目录应该类似于C:/inetpub/wwwroot/web/web

问题是 wfastcgi.py 正在寻找 C:/inetpub/wwwroot/AddressLizenzbuch/web/wsgi.py 但该路径显然不存在。你的配置文件应该包含这一行你删除非必要目录AddressLizenzbuch

<add key="PYTHONPATH" value="C:\inetpub\wwwroot\web" />

为了清楚起见,您的 wsgi.py 文件应位于 C:\inetpub\wwwroot\web\web\wsgi.py

如果您还有其他问题,请随时在 GitHub 上浏览此项目 webproject

【讨论】:

    猜你喜欢
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 2020-03-14
    • 2013-01-26
    相关资源
    最近更新 更多