Missing feature in urllib? (Getting HTTP reply code)

Yves-Eric Martin yemartin at garage.co.jp
Mon Jul 31 02:42:07 EDT 2000


    Hello everyone,


    I am now using urllib to get some data from a HTTP server, say:

import urllib
f = urllib.urlopen('http://www.nowhere.com/stuff')
readData = f.read()

    Now my problem is that wether "stuff" exists or not on the server, I
still get a readData, which can be either the actual stuff, or an error
message "404 Not found"...


    Because different servers can return different error messages (or
also because the actual data may be a 404 error message, who knows...),
I cannot rely on the data itself to decide wether to accept my readData
or to discard it: I must use the HTTP reply code to discriminate between
actual data and error messages.


    The problem is: I looked through the urllib documentation, checked
the f.headers, browsed my archives of this mailing list... I still
cannot figure out where to get this HTTP reply code...


    Is there indeed no way to get it with urllib? Maybe there is a good
reason for that (explanations welcome), but it seems like a *big*
limitation to me...


    I guess I'll have to do with httplib for now.


    Help/explanation-greatly-appreciated'ly yours.


-- 
Yves-Eric Martin
Digital Garage Inc.
yemartin at garage.co.jp




More information about the Python-list mailing list