python - 有什么方法可以让 Phusion Passenger 在 Python 3.x 中运行?

标签 python python-3.x passenger

我正在尝试使用 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 解释器。

https://stackoverflow.com/a/52582232/1630632

关于python - 有什么方法可以让 Phusion Passenger 在 Python 3.x 中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5286799/

相关文章:

python - 为什么 000 在 Python 3 中计算为 0?

python - 如何在我的代码中添加显示列数的新行

ruby-on-rails - Phusion Passenger 如何重用线程和进程?

mongodb - 连接 MongoDB 集群时 Phusion Passenger "Error: missing delimiting slash between hosts and options"错误

passenger - 如何在Ubuntu 13.10、Apache2组合中彻底卸载phusion Passenger?

python - 导入时没有名为 'PyPDF2' 的模块

python - 使用 Peewee ORM 按与 IN 中使用的列表相同的列表进行排序

python - 多个函数调用如何在 python 2.7 中工作

python - 类实例化以及抽象/静态类的变量共享

Python CSV : Find identical data in two CSV files and copy corresponding data