[Tutor] Unable to catch exception
James
jtp at nc.rr.com
Sat Aug 9 18:28:50 CEST 2008
All,
I'm having a rather strange problem that I'm hoping someone can shed
some light on. I'm trying to catch a BadStatusLine exception raised by
the httplib library. Below is the traceback that Python gives me when
something goes wrong with one of my programs:
-----
Traceback (most recent call last):
File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
self.run()
File "cherryTree.py", line 237, in run
qDump = browser.open( url ).read() # get the new c3 queue
File "/usr/lib/python2.5/site-packages/mechanize/_mechanize.py",
line 203, in open
return self._mech_open(url, data)
File "/usr/lib/python2.5/site-packages/mechanize/_mechanize.py",
line 229, in _mech_open
response = UserAgentBase.open(self, request, data)
File "/usr/lib/python2.5/site-packages/mechanize/_opener.py",
line 181, in open
response = urlopen(self, req, data)
File "/usr/lib/python2.5/urllib2.py", line 399, in _open
'_open', req)
File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/usr/lib/python2.5/site-packages/mechanize/_http.py", line
700, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.5/site-packages/mechanize/_http.py", line
675, in do_open
r = h.getresponse()
File "/usr/lib/python2.5/httplib.py", line 928, in getresponse
response.begin()
File "/usr/lib/python2.5/httplib.py", line 385, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.5/httplib.py", line 349, in _read_status
raise BadStatusLine(line)
BadStatusLine
-----
This error happens when I try to open a page using mechanize. From
what I gather this error only happens when the web server returns an
unknown error.
The error only happens once every blue moon, but to avoid a crash I
setup a try/catch.
try:
<download page code here>
catch BadStatusLine:
print "yuck!"
However, somehow the thread that this code is in still raised a
BadStatusLine exception and the thread stopped cold.
Thoughts on how to possibly fix this?
Thanks!
-j
More information about the Tutor
mailing list