>> import re-6ren">
gpt4 book ai didi

Python:使用 surveymonkey.com 请求的 SSLError

转载 作者:太空宇宙 更新时间:2023-11-03 13:45:30 24 4
gpt4 key购买 nike

Python版本:Python 2.7.6

操作系统:OSX 10.10.3

我正在尝试 requests "https://www.surveymonkey.com/ "

>>> import requests
>>> requests.get('https://www.surveymonkey.com/')

但我收到以下错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno bad handshake] [('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')]

我没有得到与“https://www.google.com”相同的错误

>>> import requests
>>> requests.get('https://www.google.com')
<Response [200]>

这是否意味着 surveymonkey 的 ssl 有问题?

Python 版本:2.7.10

>>> requests.get('https://www.surveymonkey.com/mp/legal/which-terms-apply')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)

更新:我试过 Python 2.7.6、Python 2.7.9、Python 2.7.10

使用操作系统:OSX 10.10.3 和 OpenSSL 1.0.2d 2015 年 7 月 9 日。请求版本 2.4.3、2.5.3、2.7.0。

我试过 configure the ssl protocol. Python 2.7.10/Requests 2.7.0 以下是代码:

import ssl
import requests

from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager


class Ssl3HttpAdapter(HTTPAdapter):
""""Transport adapter" that allows us to use SSLv3."""

def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=ssl.PROTOCOL_SSLv3)

s = requests.Session()
s.mount('https://', Ssl3HttpAdapter())
url = 'https://www.surveymonkey.com/'
print s.get(url)

我仍然遇到错误:

Traceback (most recent call last):
File "redirect.py", line 29, in <module>
print s.get(url)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py", line 469, in get
return self.request('GET', url, **kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/adapters.py", line 420, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)

最佳答案

我无法在我的机器上重现它(Py 3.4.2/2.7.9、请求 2.4.3、请求 2.7.0、OpenSSL 1.0.1k、Debian Jessie)。我在一些使用旧 OpenSSL 版本的机器上看到了类似的消息。

您可以尝试升级您的 Python/OpenSSL(旧版本的 Python 附带旧的 OpenSSL 版本)或通过使用 OpenSSL 命令行工具进行测试并改变选项来深入挖掘。告诉我们您使用的是哪个操作系统和哪个 Python 版本可能会有所帮助。

openssl s_client -connect www.surveymonkey.com:443

请参阅 SSL 实验室,以人性化的格式获取受支持的 TLS 版本和服务器密码。 https://www.ssllabs.com/ssltest/analyze.html?d=www.surveymonkey.com

按照建议,您可以尝试强制使用某个 TLS 版本或更改支持的密码列表。据我所知,似乎没有什么好的方法可以通过 API 影响密码。

由于它对某些人有效而对其他人无效,我们可能想比较不同版本中使用的默认密码。将其更改为 ALL should 可能会使它工作,但不是很安全,因此应该找出哪个限制是罪魁祸首。 SSL Labs 网站可助您一臂之力。

请参阅下面的代码,了解如何更改默认的 chiphers 列表:

import requests.packages.urllib3.util.ssl_
print(requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS)
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL'

关于Python:使用 surveymonkey.com 请求的 SSLError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31730819/

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