URLError

Jim justjpm at aol.com
Thu Mar 20 13:26:14 EDT 2008


On Mar 19, 6:50 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> 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 returnshtmlcode 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

Thanks Steven for recommendation.

The program is my first and I'm not a programmer so it will take me
some time to get your recommendation to work. So far the program runs
after I added code based on your example but the program still aborts
and none of the code ("Temporary failure, Skip/Halt/try Again?" or
"Unknown response, boo hiss to you!") in your example is displayed. It
appears to abort in the imported module "urllib2" which is open
source. The code in urllib2 is way over my skill level.

Jim



More information about the Python-list mailing list