2005-08-16

Hmmmm.

urllib2 - The Missing Manual: Coping With Errors:

"urlopen raises URLError or HTTPError in the event of an error. HTTPError is a subclass of URLError, which is a subclass of IOError. This means you can trap for IOError if you want."

  req = urllib2.Request(some_url)
  try:
    handle = urllib2.urlopen(req)
  except IOError:
    print 'Something went wrong'
  else:
    print handle.read()

No comments: