Python:在Windows上执行而不是linux

时间:2016-07-16 20:37:12

标签: windows ssl python-requests python-3.4 handshake

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

以下是生成错误的代码:

   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但仍然没有。

感谢您的建议

1 个答案:

答案 0 :(得分:1)

网站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,了解如何通过启用不安全的密码来解决此问题。