windows - python : bad handshake error on get request when executed on windows but not linux

标签 windows ssl python-requests python-3.4 handshake

我写了一个 python 脚本来下载网站的内容,当我在 linux 机器上执行它时它工作得很好,但在 windows 上却不行(它需要在 windows 上执行)。

这是生成错误的代码:

   import requests
   c = requests.Session()
   url = 'https://ted.jeancoutu.com/action/login'
   c.get(url)

这是我在 Windows 机器上执行代码时收到的错误消息:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\contrib\pyopenssl.py", line 348, in ssl_wrap_socket
    cnx.do_handshake()
  File "C:\Python34\lib\site-packages\OpenSSL\SSL.py", line 1443, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Python34\lib\site-packages\OpenSSL\SSL.py", line 1191, in _raise_ssl_error
    _raise_current_error()
  File "C:\Python34\lib\site-packages\OpenSSL\_util.py", line 48, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 578, in urlopen
    chunked=chunked)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 351, in _make_request
    self._validate_conn(conn)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 814, in _validate_conn
    conn.connect()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 289, in connect
    ssl_version=resolved_ssl_version)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\contrib\pyopenssl.py", line 355, in ssl_wrap_socket
    raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')],)",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 403, in send
    timeout=timeout
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 604, in urlopen
    raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')],)",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 487, in get
    return self.request('GET', url, **kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 477, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')],)",)

我找不到这个问题的解决方案。我尝试了很多在网上找到的建议,但没有任何效果。我安装了 pyOpenSSL、ndg-httpsclient 和 pyasn1,但没有结果。我也升级了 ssl,但仍然没有。

谢谢你的建议

最佳答案

网站 ted.jeancoutu.com 仅支持 RC4-SHA 和 RC4-MD5 密码(参见 SSLLabs report。RC4 密码被认为是不安全的,因此已从 version 2.5.2 in 02/2015 的请求中的默认密码集中删除。您可能在 Linux 上使用旧版本的请求,因此它仍然有效,但在 Windows 上使用较新版本时失败。

参见 https://stackoverflow.com/a/32651967/3081018了解如何通过启用不安全密码来解决问题。

关于windows - python : bad handshake error on get request when executed on windows but not linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38415410/

相关文章:

windows - 使用 xperf 获取符号

Windows 上的 iPhone 应用程序开发

Windows 上下文菜单运行隐藏的 xcopy

performance - 带有 .htaccess 的选择性 SSL 强制 http ://or https://

python - 使用请求选择和上传 pdf 文件时遇到问题

windows - 如何确定 Windows XP- X86 上的机器字节顺序

java - HttpGet 的 SSL 问题可能是因为服务器正在请求客户端身份验证

flutter - 如何在flutter中固定SSL证书的公钥?

python - 如何使用 Python Requests 库在 post 请求中发送 cookie?

python - 通过 Tor 进行多线程 Python 请求