[Tutor] urllib2 sslerror

Johan Geldenhuys johan at accesstel.com.au
Fri Oct 7 07:44:59 CEST 2011


Hi everybody,

Almost weekend, hang in there.

I need some advice and hope somebody can help me.

I have the follow piece of code that I use to get some data from a https
webpage.

-------------------------------------------------------
< some other stuff up here>
try:
    return_object = urllib2.urlopen(theurl)
    html_content = return_object.read()
                      
    now = time.strftime("%Y%m%d%H%M%S")
    img_file = "%s_%s.jpg"% (location, now)
    f = open(img_file, 'wb')
    f.write(html_content)
    f.close()
    file = img_file
except Exception, e:
	print e

<some other stuff down here>
-------------------------------------------------------

Sometimes I get the following error and I don't know why. It occurs very
randomly and is hard or nearly impossible to reproduce (maybe there is
somebody who knows how to create it).

-------------------------------------------------------
Traceback (most recent call last):
  File "/var/ai-muse/jail/pkgdb/camimage/getimage.py", line 74, in run
    return_object = urllib2.urlopen(self.theurl)
  File "/usr/lib/python2.2/urllib2.py", line 138, in urlopen
  File "/usr/lib/python2.2/urllib2.py", line 322, in open
  File "/usr/lib/python2.2/urllib2.py", line 301, in _call_chain
  File "/usr/lib/python2.2/urllib2.py", line 792, in https_open
  File "/usr/lib/python2.2/urllib2.py", line 779, in do_open
  File "/usr/lib/python2.2/urllib2.py", line 342, in error
  File "/usr/lib/python2.2/urllib2.py", line 301, in _call_chain
  File "/usr/lib/python2.2/urllib2.py", line 611, in http_error_401
  File "/usr/lib/python2.2/urllib2.py", line 590, in http_error_auth_reqed
  File "/usr/lib/python2.2/urllib2.py", line 600, in retry_http_basic_auth
  File "/usr/lib/python2.2/urllib2.py", line 322, in open
  File "/usr/lib/python2.2/urllib2.py", line 301, in _call_chain
  File "/usr/lib/python2.2/urllib2.py", line 792, in https_open
  File "/usr/lib/python2.2/urllib2.py", line 774, in do_open
  File "/usr/lib/python2.2/httplib.py", line 752, in getreply
  File "/usr/lib/python2.2/httplib.py", line 593, in getresponse
  File "/usr/lib/python2.2/httplib.py", line 99, in __init__
  File "/usr/lib/python2.2/httplib.py", line 628, in makefile
sslerror: (5, 'EOF occurred in violation of protocol')
------------------------------------------------------------


Any idea why it happens randomly and how I can check the cause?
I read on a Google search page that one guy had the same issue and traced it
back to some characters in the data he was receiving. Could that cause it?

Thanks in advance
  
Johan 




More information about the Tutor mailing list