在python27和python36中运行wsgi时出错

时间:2017-04-17 06:18:42

标签: python python-2.7 python-3.x

我下载了mod_fcgid-2.3.9并在Apache 2.4下使用它。 我在python 2.7中做了一个'pip install flup',并尝试运行以下代码来测试wsgi。

from cgi import escape
import sys, os
from flup.server.fcgi import WSGIServer

def app(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    yield '<h1>FastCGI Environment</h1>'

    yield '<table>'
    for k, v in sorted(environ.items()):
        yield '<tr><th>%s</th><td>%s</td></tr>' % (escape(k), escape(v))
    yield '</table>'

WSGIServer(app).run()

然而,遇到以下错误

Traceback (most recent call last):
  File "C:\Users\jl\Documents\00-wsgi.py", line 18, in <module> WSGIServer(app).run()
  File "C:\Python27\lib\site-packages\flup\server\fcgi.py", line 112, in run
    sock = self._setupSocket()
  File "C:\Python27\lib\site-packages\flup\server\fcgi_base.py", line 978, in _setupSocket
    sock = socket.fromfd(FCGI_LISTENSOCK_FILENO, socket.AF_INET,
AttributeError: 'module' object has no attribute 'fromfd'

我试图在python36下运行上面的内容。 我在python36环境下做了'pip install flup6',然后运行上面的程序并遇到以下错误。

Traceback (most recent call last):
  File "C:/Users/jl/Documents/00-wsgi36.py", line 20, in <module>
    WSGIServer(app).run()
  File "C:\Python36\lib\site-packages\flup\server\fcgi.py", line 112, in run
    sock = self._setupSocket()
  File "C:\Python36\lib\site-packages\flup\server\fcgi_base.py", line 988, in _setupSocket
    socket.SOCK_STREAM)
  File "C:\Python36\lib\socket.py", line 460, in fromfd
    nfd = dup(fd)
OSError: [WinError 10038] An operation was attempted on something that is not a socket

如何解决python27和python36环境中的问题?

0 个答案:

没有答案