问题描述
在使用MacOS X的Python中,尝试向网站发出POST请求,但出现以下错误post_response = session.post(post_url, data=post_payload, headers=post_headers)
:
In Python using MacOS X, made an attempt to make a POST request to a website but I got the following error post_response = session.post(post_url, data=post_payload, headers=post_headers)
:
Traceback (most recent call last):
File "web_requests.py", line 424, in <module>
main()
File "web_requests.py", line 340, in main
post_response = session.post(post_url, data=post_payload, headers=post_headers)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 535, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/Library/Python/2.7/site-packages/requests/adapters.py", line 497, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)
可能是什么问题?
预先感谢您,一定会赞成/接受答案
Thank you in advance and will be sure to upvote/accept answer
编辑
特定于Python中的POST请求
Specific to POST requests in Python
推荐答案
根据此站点SSLLabs报告的注释中的其他信息,该报告仅支持TLS 1.2:
According to the addititional information in the comment SSLLabs reports for this site that it support TLS 1.2 only:
TLS 1.2 Yes
TLS 1.1 No
TLS 1.0 No
SSL 3 No
根据注释中的其他信息,OpenSSL版本为0.9.8:
And according to another information in the comments the OpenSSL version is 0.9.8:
由于OpenSSL 0.9.8仅支持最多TLS 1.0,尤其是不支持TLS 1.2,因此客户端和服务器之间没有通用的TLS协议.因此,握手失败.
Since OpenSSL 0.9.8 only support up to TLS 1.0 and especially not TLS 1.2 there is no common TLS protocol spoken between the client and the server. Thus, the handshake fails.
解决问题的方法是将Python使用的OpenSSL版本从非常老的版本升级到至少OpenSSL 1.0.1.有关更多信息,请参见例如更新python 2.7中的openssl 或使用 Anaconda Python 预装了很多模块,还包括当前版本的OpenSSL.
The way to fix the problem is to upgrade the version of OpenSSL as used by Python away from the very old version to at least OpenSSL 1.0.1. See for example Updating openssl in python 2.7 for more information or use Anaconda Python which comes preinstalled with a lot of modules and also includes a current version of OpenSSL.
这篇关于Python/请求:requests.exceptions.SSLError:[SSL:SSLV3_ALERT_HANDSHAKE_FAILURE]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!