gpt4 book ai didi

python - 属性错误 : 'Context' object has no attribute 'wrap_socket'

转载 作者:IT老高 更新时间:2023-10-28 22:10:24 32 4
gpt4 key购买 nike

我正在尝试设置一个使用 OpenSSL 上下文的 Flask 服务器。但是,由于我将脚本移动到不同的服务器上,因此无论我使用的是 Python 2.7 还是 3.4,也无论我选择了哪种 SSL 方法(SSLv23/TLSv1/...),它都会不断抛出以下错误:

  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "/usr/lib/python3.4/threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 602, in inner
passthrough_errors, ssl_context).serve_forever()
File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 506, in make_server
passthrough_errors, ssl_context)
File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 450, in __init__
self.socket = ssl_context.wrap_socket(self.socket,
AttributeError: 'Context' object has no attribute 'wrap_socket'

相应代码如下:

if __name__ == "__main__":
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('key.key')
context.use_certificate_file('cert.crt')
app.run(host='0.0.0.0', port=80, ssl_context=context, threaded=True, debug=True)

提前非常感谢您!我很高兴得到任何帮助

最佳答案

从 0.10 开始,Werkzeug 不再支持 OpenSSL 上下文。做出这个决定是因为它更容易支持 ssl.SSLContext跨 Python 版本。您可以选择重写此代码:

if __name__ == "__main__":
context = ('cert.crt', 'key.key')
app.run(host='0.0.0.0', port=80, ssl_context=context, threaded=True, debug=True)

http://werkzeug.pocoo.org/docs/latest/serving/所有的可能性。

关于python - 属性错误 : 'Context' object has no attribute 'wrap_socket' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28579142/

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