【问题标题】:WSGI Python adapter to test FastCGI: Error starting WSGI server用于测试 FastCGI 的 WSGI Python 适配器:启动 WSGI 服务器时出错
【发布时间】:2016-01-03 07:00:36
【问题描述】:

当我尝试运行 WSGI Python 脚本以从 tutorial 测试 FastCGI 时:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

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()

它会导致以下结果,从错误日志中,根据返回的应用状态 0 并不清楚出了什么问题。可能是我遗漏了一些东西。

Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

  File "/usr/local/lib64/python2.7/site-packages/mod_python/apache.py", line 398, in HandlerDispatch
    result = obj(req)

  File "/usr/local/lib64/python2.7/site-packages/mod_python/publisher.py", line 213, in handler
    module = page_cache[req]

  File "/usr/local/lib64/python2.7/site-packages/mod_python/cache.py", line 89, in __getitem__
    return self._checkitem(name)[2]

  File "/usr/local/lib64/python2.7/site-packages/mod_python/cache.py", line 131, in _checkitem
    value = self.build(key, name, opened, entry)

  File "/usr/local/lib64/python2.7/site-packages/mod_python/publisher.py", line 86, in build
    return ModuleCache.build(self, key, req, opened, entry)

  File "/usr/local/lib64/python2.7/site-packages/mod_python/cache.py", line 380, in build
    exec(opened_as_str, module.__dict__)

  File "<string>", line 21, in <module>

  File "/usr/local/lib/python2.7/site-packages/flup/server/fcgi.py", line 112, in run
    sock = self._setupSocket()

  File "/usr/local/lib/python2.7/site-packages/flup/server/fcgi_base.py", line 997, in _setupSocket
    req.run()

  File "/usr/local/lib/python2.7/site-packages/flup/server/fcgi_base.py", line 572, in run
    self._end(appStatus, protocolStatus)

  File "/usr/local/lib/python2.7/site-packages/flup/server/fcgi_base.py", line 601, in _end
    sys.exit(appStatus)

SystemExit: 0

一个提示可能是它仅在我通过 Apache 运行它时发生。在命令行中它工作正常。

【问题讨论】:

    标签: apache mod-wsgi fastcgi httpd.conf mod-python


    【解决方案1】:

    看起来您正在尝试通过 FCGI 运行 WSGI 应用程序,但使用的是 mod_python。如果必须使用 FCGI,则需要使用 mod_fastcgi。但是,实际上您应该单独使用 mod_wsgi ,而不要使用它或 Flup。

    【讨论】:

      猜你喜欢
      • 2018-06-11
      • 2020-12-04
      • 1970-01-01
      • 2021-08-06
      • 2014-06-22
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      相关资源
      最近更新 更多