系统相关
首页 > 系统相关> > 某些站点的Python HTTPS请求(urllib2)在没有代理的Ubuntu 12.04上失败

某些站点的Python HTTPS请求(urllib2)在没有代理的Ubuntu 12.04上失败

作者:互联网

我有一个用Python编写的小应用程序它曾经工作……直到昨天,它突然开始在HTTPS连接中给我一个错误.我不记得是否有更新,但Python 2.7.3rc2和Python 3.2都失败了.

我搜索了它,发现当人们在代理后面时会发生这种情况,但我不是(自上次工作以来我的网络没有任何变化).我的syster的运行Windows和Python 2.7.2的计算机没有问题(在同一网络中).

>>> url = 'https://www.mediafire.com/api/user/get_session_token.php'
>>> response = urllib2.urlopen(url).read()
  File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 400, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 418, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1215, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1177, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 8] _ssl.c:504: EOF occurred in violation of protocol>

怎么了?任何帮助表示赞赏.

PS.:旧的python版本也不工作,不在我的系统中,也不在USB的实时会话中,但是DO在Ubuntu 11.10实时会话中工作.

解决方法:

这似乎与在12.04中发现的OpenSSL版本中添加TLS 1.1和1.2支持有关.可以使用OpenSSL命令行工具重现连接失败:

$openssl s_client -connect www.mediafire.com:443
CONNECTED(00000003)
140491065808544:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:177:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 320 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---

如果我强制连接使用带有-tls1命令行参数的TLS 1.0,则连接成功.

我建议你在这里提交一个关于这个问题的bug报告:

https://bugs.launchpad.net/ubuntu/+filebug

标签:python,ssl,https,12-04
来源: https://codeday.me/bug/20190807/1611934.html