【问题标题】:Problems getting the Heroku example app for Python run locally with SSL使用 SSL 在本地运行 Python 的 Heroku 示例应用程序时出现问题
【发布时间】:2011-11-26 16:42:54
【问题描述】:

我开始遇到与this question 相同的问题。正如其中一个答案所暗示的那样,可以通过使应用程序在没有 SSL 的情况下运行来避免该特定问题。但由于 Facebook 将在短短几天内(2011 年 10 月 1 日)为应用程序强制实施 https,这似乎是一个不会持久的解决方案。我首先尝试在 app.run 中启用 ssl(在exampleapp.py 的第 149 行附近。像这样:

app.run(host='0.0.0.0', port=port, ssl_context='adhoc')

第一次尝试失败,开始抱怨缺少 OpenSSL 模块。在网上找到了一些关于如何解决这个问题的建议,然后选择这样做:

(myapp)$ pip install pyopenssl

现在开始时没有投诉:

(myapp)$ foreman start
10:35:25 web.1     | started with pid 26934
10:35:26 web.1     |  * Running on https://0.0.0.0:5000/
10:35:26 web.1     |  * Restarting with reloader

但是当尝试访问应用程序时:

10:35:31 web.1     | ----------------------------------------
10:35:31 web.1     | Exception happened during processing of request from ('127.0.0.1', 61118)
10:35:31 web.1     | Traceback (most recent call last):
10:35:31 web.1     |   File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
10:35:31 web.1     |     self.process_request(request, client_address)
10:35:31 web.1     |   File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 310, in process_request
10:35:31 web.1     |     self.finish_request(request, client_address)
10:35:31 web.1     |   File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 323, in finish_request
10:35:31 web.1     |     self.RequestHandlerClass(request, client_address, self)
10:35:31 web.1     |   File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 639, in __init__
10:35:31 web.1     |     self.handle()
10:35:31 web.1     |   File "path_to_myapp/lib/python2.7/site-packages/werkzeug/serving.py", line 189, in handle
10:35:31 web.1     |     return rv
10:35:31 web.1     | UnboundLocalError: local variable 'rv' referenced before assignment
10:35:31 web.1     | ----------------------------------------
10:35:31 web.1     | Unhandled exception in thread started by <function inner at 0x10139e050>
10:35:31 web.1     | Traceback (most recent call last):
10:35:31 web.1     |   File "path_to_myapp/lib/python2.7/site-packages/werkzeug/serving.py", line 599, in inner
10:35:31 web.1     |     passthrough_errors, ssl_context).serve_forever()
10:35:31 web.1     |   File "path_to_myapp/lib/python2.7/site-packages/werkzeug/serving.py", line 355, in serve_forever
10:35:31 web.1     |     HTTPServer.serve_forever(self)
10:35:31 web.1     |   File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 227, in serve_forever
10:35:31 web.1     |     self._handle_request_noblock()
10:35:31 web.1     |   File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 287, in _handle_request_noblock
10:35:31 web.1     |     self.shutdown_request(request)
10:35:31 web.1     |   File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 459, in shutdown_request
10:35:31 web.1     |     request.shutdown(socket.SHUT_WR)
10:35:31 web.1     | TypeError: shutdown() takes exactly 0 arguments (1 given)

怎么办?是错误的 Python 版本还是只是我误解了其他一些基本的东西?

【问题讨论】:

    标签: python facebook heroku openssl virtualenv


    【解决方案1】:

    这是 Werkzeug 中的一个错误,得到了fixed

    requirements.txt 文件中的 Werkzeug 版本更改为至少 0.8.2 并运行 pip install -r requirements.txt 进行升级。

    【讨论】:

      【解决方案2】:

      如果不检查本地环境、脚本、已安装的模块和 werkzeug 代码(声称从 v0.6 开始支持 SSL),很难确定“rv”为什么会失败。

      最简单的解决方案是在本地机器上安装 apache 的爷爷网络服务器,添加 mod_ssl 模块并生成这些 SSL 证书。最后,按照 Flask 的help page 中的说明添加 mod_wsgi 以启动并运行您的应用程序。

      注意:对于初学者来说,安装可能会让人望而生畏,但一旦开始,apache 就会成为主力,并且在过去 15 年里对我来说非常可靠。

      【讨论】:

        猜你喜欢
        • 2011-11-24
        • 2011-04-07
        • 2015-08-30
        • 2020-06-22
        • 2014-07-18
        • 2013-04-07
        • 1970-01-01
        • 2014-03-17
        • 1970-01-01
        相关资源
        最近更新 更多