URLError
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Wed Mar 19 18:50:40 EDT 2008
On Wed, 19 Mar 2008 14:45:39 -0700, Jim wrote:
> Program randomly aborts when looking up url. The program loop thru
> 4000+ records looking
> up ID via internet and returns html code which is used in subsequent
> processing. The code
> for looking-up record is below followed by abort details. Can anyone
> help with catching the
> abort before program aborts or provide code to automatically start
> program?
Yes. Wrap the offending code with a try...except loop, something similar
to this.
try:
contents = urllib2.urlopen(url).read()
except URLError, e:
if e.errno == 10053:
# "Software caused connection abort"
response = raw_input(
"Temporary failure, Skip/Halt/try Again?")
response = response.lower().strip()
if response in ('h', 'halt'):
break
elif response in ('a', 'again', 't', 'try', 'try again'):
continue
elif response in ('', 's', 'skip'):
lines -= 1
continue
else:
print "Unknown response, boo hiss to you!"
raise
--
Steven
More information about the Python-list
mailing list