checking for file existance

Matt Gushee mgushee at havenrock.com
Sun Jan 16 11:29:46 EST 2000


Oleg Broytmann <phd at phd.russ.ru> writes:

> On Wed, 12 Jan 2000, Anders M Eriksson wrote:
> > How do I check if a file exist on a webserver? I have tried
> > urllib.urlopen() but it never give any exception IOError.
> 
>    There is no such thing as "file-by-WWW". URL gives you a reference to an
> object, and if a WWW server can't resolve the reference, it is not
> mandatory to return the error 404 - WWW server may decide to return another
> object (a page with words and picture saying you have got an error).

If you use httplib instead of urllib, you can access the HTTP status
codes. However, as Oleg points out, you can't always depend on those
codes, so it's questionable whether it's worthwhile.

-- 
Matt Gushee
Portland, Maine, USA
mgushee at havenrock.com
http://www.havenrock.com/



More information about the Python-list mailing list