Ubuntu12.04のPythonでurllib2を使ったhttps通信で下記エラーが出た時の対象例
<urlopen error [Errno 8] _ssl.c:504: EOF occurred in violation of protocol>
------------------------------------------------
import urllib2
import ssl
from functools import wraps
def sslwrap(func):
@wraps(func)
def bar(*args, **kw):
kw['ssl_version'] = ssl.PROTOCOL_TLSv1
return func(*args, **kw)
return bar
ssl.wrap_socket = sslwrap(ssl.wrap_socket)
url = 'https://xxxx.xx.xx'
reqObj = urllib2.urlopen(url)
print reqObj.code
print reqObj.msg
print reqObj.headers
response = reqObj.read()
print response
ここを参考にしました。
http://stackoverflow.com/questions/14102416/python-requests-requests-exceptions-sslerror-errno-8-ssl-c504-eof-occurred