nntplib: how to access NNTP response codes on exceptions?

Andrew Markebo andrew.markebo at telia.com
Thu Apr 3 05:25:36 EST 2003


| I get the exception nntplib.NNTPTemporaryError as documented in
| http://www.python.org/doc/current/lib/module-nntplib.html .  But
| NNTPTemporaryError is raised for any response code in the range
| 400-499.  Is there a way of determining the particular response code?
| Ordinarily, it would be the first three characters in the first
| element ("resp", in my example) returned from the nntplib method
| (whether head, stat, etc.).  But because of the exception, the
| assignment to the tuple never occurs, so I can't check it.

If you catch it through something like:

 except NNTPTemporaryError, e:

The response is put in e.response, so you can find the code in the
first three characters.. 

You might have missed that parameters can be thrown with the
exceptions, and thats what e is.. an instansiation of a
NNTPTemporaryError class.

                   /Andy

-- 
 The eye of the linker rests on the libs!




More information about the Python-list mailing list