Python:SSLError 使用对surveymonkey.com 的请求 [英] Python: SSLError using requests for surveymonkey.com

查看:46
本文介绍了Python:SSLError 使用对surveymonkey.com 的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 版本:Python 2.7.6

操作系统:OSX 10.10.3

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

<预><代码>>>>进口请求>>>requests.get('https://www.surveymonkey.com/')

但我收到以下错误:

回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/api.py",第 69 行,在 get返回请求('get', url, params=params, **kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/api.py",第 50 行,请求response = session.request(method=method, url=url, **kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py",第 465 行,请求resp = self.send(prep, **send_kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py",第573行,发送r = adapter.send(request, **kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/adapters.py",第431行,发送引发 SSLError(e, request=request)requests.exceptions.SSLError: [Errno bad handshake] [('SSL 例程', 'SSL23_GET_SERVER_HELLO', 'sslv3 警报握手失败')]

我在使用https://www.google.com"时没有遇到同样的错误><预><代码>>>>进口请求>>>requests.get('https://www.google.com')<响应[200]>

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

Python 版本:2.7.10

<预><代码>>>>requests.get('https://www.surveymonkey.com/mp/legal/which-terms-apply')回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/api.py",第 69 行,在 get返回请求('get', url, params=params, **kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/api.py",第 50 行,请求response = session.request(method=method, url=url, **kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py",第 465 行,请求resp = self.send(prep, **send_kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py",第573行,发送r = adapter.send(request, **kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/adapters.py",第431行,发送引发 SSLError(e, request=request)requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 警报握手失败 (_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.

我试过 配置ssl协议. Python 2.7.10/Requests 2.7.0 以下是代码:

导入ssl进口请求从 requests.adapters 导入 HTTPAdapter从 requests.packages.urllib3.poolmanager 导入 PoolManager类 Ssl3HttpAdapter(HTTPAdapter):""""传输适配器"允许我们使用 SSLv3."""def init_poolmanager(self, connections, maxsize, block=False):self.poolmanager = PoolManager(num_pools=connections,最大尺寸=最大尺寸,块=块,ssl_version=ssl.PROTOCOL_SSLv3)s = requests.Session()s.mount('https://', Ssl3HttpAdapter())url = 'https://www.surveymonkey.com/'打印 s.get(url)

我仍然收到错误消息:

回溯(最近一次调用最后一次): 中的文件redirect.py",第 29 行打印 s.get(url)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py",第 469 行,在 get返回 self.request('GET', url, **kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py",第 457 行,请求resp = self.send(prep, **send_kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/sessions.py",第569行,发送r = adapter.send(request, **kwargs)文件/Users/jasony/Documents/python/scripts2/env/lib/python2.7/site-packages/requests/adapters.py",第420行,发送引发 SSLError(e, request=request)requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 警报握手失败 (_ssl.c:590)

解决方案

我无法在我的机器上重现这个问题 (Py 3.4.2/2.7.9, requests 2.4.3, requests 2.7.0, OpenSSL 1.0.1k, Debian杰西).我在一些使用旧 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 应该可能会使其工作,但不是很安全,因此应该找出哪个限制是罪魁祸首.SSL Labs 网站可帮助您解决此问题.

有关如何更改默认芯片组列表的信息,请参阅以下代码:

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

Python Version: Python 2.7.6

OS: OSX 10.10.3

I'm trying to requests "https://www.surveymonkey.com/"

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

but I get the following error:

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')]

I don't get the same error with "https://www.google.com"

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

Does this mean there is an issue with surveymonkey's ssl?

Python Version: 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)

Update: I've tried Python 2.7.6, Python 2.7.9, Python 2.7.10

with OS: OSX 10.10.3 with OpenSSL 1.0.2d 9 Jul 2015. Requests versions 2.4.3, 2.5.3, 2.7.0.

I've tried to configure the ssl protocol. Python 2.7.10 / Requests 2.7.0 The following is the code:

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)

I still get an error:

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)

解决方案

I cannot reproduce this on my machine (Py 3.4.2/2.7.9, requests 2.4.3, requests 2.7.0, OpenSSL 1.0.1k, Debian Jessie). I have seen similar messages on some machines with old OpenSSL versions.

You might try upgrading your Python/OpenSSL (old versions of Python ship with old OpenSSL versions) or digging deeper by testing using the OpenSSL command line tool and varying the options to dig deeper. It might be helpful to tell us on which OS and which Python version you are on.

openssl s_client -connect www.surveymonkey.com:443

See SSL Labs to get the supported TLS versions and ciphers of the server in a human-friendly format. https://www.ssllabs.com/ssltest/analyze.html?d=www.surveymonkey.com

As suggested you might try to force a certain TLS version or change the list of supported ciphers. It seems like there is not nice way to influence the ciphers via the API as far as I know.

Since it works for some people and does not for others, we might want to compare the default ciphers used in different versions. Changing it to ALL should will likely make it work, but is not very secure, so one should find out which restriction is the culprit. The SSL Labs website helps you with that.

See the code below on how to change the default chiphers list:

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

这篇关于Python:SSLError 使用对surveymonkey.com 的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆