我正在尝试使用 Phusion Passenger 运行 Python 3 WSGI 应用程序。使用来自 this question 的信息,我可以让 Passenger 使用 Python 3,但似乎不可能在 Python 2.x 中使用 Passenger 运行 Python 3 应用程序(即,应用程序和 Passenger 似乎都必须在同一个 Python 解释器中运行)。因此我假设我需要让 Passenger 在 3.x 中工作。
我在 Passenger 的 request_handler.py 上运行了 2to3,然后计算出了剩余的运行时错误。但是,当我运行该应用程序时,我只在日志中收到带有此错误的 502:
[error] 9839#0: *4 upstream prematurely closed connection while reading response header from upstream, client: …, server: _, request: "GET / HTTP/1.1", upstream: "passenger:unix:/passenger_helper_server:", host: "…"
相同的应用程序代码确实适用于 Python 2.x 中的 Passenger,因此我假设它与我的 request_handler.py 的 2to3 迁移有关。以下是我所做更改的差异。有任何想法吗?谢谢!
27c26
< import traceback
---
> import exceptions, traceback
29c28
< from socket import SocketIO
---
> from socket import _fileobject
65c64
< except Exception as e:
---
> except Exception, e:
67c66
< sys.stderr.write(str(e.__class__) + ": " + str(e) + "\n")
---
> sys.stderr.write(str(e.__class__) + ": " + e.message + "\n")
84c83
< buf = b''
---
> buf = ''
92c91
< buf = b''
---
> buf = ''
99c98
< headers = buf.split(b"\0")
---
> headers = buf.split("\0")
117c116
< env['wsgi.input'] = SocketIO(input_stream,'r',512)
---
> env['wsgi.input'] = _fileobject(input_stream,'r',512)
155c154
< raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
---
> raise exc_info[0], exc_info[1], exc_info[2]
最佳答案
现代答案:
您可以通过服务器配置、虚拟主机、目录或 .htaccess 文件中的 PassengerPython 变量指定 python 解释器。
关于python - 有什么方法可以让 Phusion Passenger 在 Python 3.x 中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5286799/