Workaround for Python ssl library

When you got <urlopen error [Errno 8] _ssl.c:504: EOF occurred in violation of protocol> in self.sslobj.dohandshake, you could fix it like this:

import functools
import ssl

old_init = ssl.SSLSocket.__init__

@functools.wraps(old_init)
def ubuntu_openssl_bug_965371(self, *args, **kwargs):
    kwargs['ssl_version'] = ssl.PROTOCOL_TLSv1
    old_init(self, *args, **kwargs)

ssl.SSLSocket.__init__ = ubuntu_openssl_bug_965371

Ref Python HTTPS requests (urllib2) to some sites fail on Ubuntu 12.04 without proxy

喜欢这篇文章就分享到微博吧!
留言请发送到
微信公众帐号
“技术派”

修订历史:


知识共享许可协议

关注@好看簿的蚂蚁

探讨技术、设计、人文和商业
相关的创业话题