Python请求SSL23_GET_SERVER_HELLO或SSL3_GET_RECORD错误

时间:2016-09-30 02:55:12

标签: python python-2.7 ssl amazon-s3 python-requests

我正在使用OpenSSL 1.0.1运行Python 2.7.3应用程序:

Python 2.7.3 (default, Jun 22 2015, 19:33:41) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.1 14 Mar 2012'

最初,我这样做了:

import requests
_session = requests.Session()
_session.get('https://bucketname.s3.amazonaws.com/file.name')

这导致以下错误:

  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 497, in send
    raise SSLError(e, request=request)
SSLError: [Errno 1] _ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

https://github.com/kennethreitz/requests/issues/606及其与http://toolbelt.readthedocs.io/en/latest/user.html#ssladapter的链接上进行了大量Google搜索和绊脚后,我尝试了这个:

import requests
import requests_toolbelt
_session = requests.Session()
_session.mount('https://', requests_toolbelt.SSLAdapter(ssl.PROTOCOL_TLSv1))
_session.get('https://bucketname.s3.amazonaws.com/file.name')

但这会导致不同的错误:

  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 497, in send
    raise SSLError(e, request=request)
SSLError: [Errno 1] _ssl.c:504: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

无论我做什么,我都无法获得Python请求来访问此URL。我只是没有得到它。应该很简单。它应该工作,但它不会。

有什么想法吗?

0 个答案:

没有答案