More Pythonic?

Aahz Maruch aahz at netcom.com
Fri Sep 17 18:20:59 EDT 1999


In article <14303.48361.981801.869073 at bitdiddle.cnri.reston.va.us>,
Jeremy Hylton  <jeremy at cnri.reston.va.us> wrote:
>>>>>> "AM" == Aahz Maruch <aahz at netcom.com> writes:
>
>The proper way to use the code would be:
>
>import urllib2
>try:
>    resp = urllib2.urlopen('http://frob.nitz/')
>except urllib2.HTTPError, resp:
>    print resp.code, resp.msg

Got it, thanks.  It's always interesting when you explore a new area of
the language.  Just to make sure I understand this, am I correct in
thinking that getting the exception object the way you show here is
better than using sys.exc_info()?

>  AM> Overall, your code looks similar to the code I was planning to
>  AM> write, but the big feature your code is missing is the stack of
>  AM> redirects.
>
>I'm not entirely clear on what the "stack of redirects" feature is.  I 
>assume you're concenred about a case with multiple redirects, e.g.
>   URL1 -> URL2 -> URL3 -> URL4,
>where the last redirect raises an error.  What do you want to do at
>this point?  The Python call stack does contain separate request
>objects for each redirect, but it isn't obvious how to do anything
>with them.

That's precisely correct.  It isn't so much for socket errors that I'd
need the info as for other kinds of server errors, and *definitely* for
non-errors.  For example, if each URL is on a different server, I might
want to retrieve robots.txt from each server.
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>      http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6  (if you want to know, do some research)




More information about the Python-list mailing list