gpt4 book ai didi

python - 使用 SSL 在本地运行适用于 Python 的 Heroku 示例应用程序时出现问题

转载 作者:太空狗 更新时间:2023-10-30 00:15:25 24 4
gpt4 key购买 nike

我开始遇到与 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 版本还是我误解了其他一些基本知识?

最佳答案

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

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

关于python - 使用 SSL 在本地运行适用于 Python 的 Heroku 示例应用程序时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7580660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com