urllib.urlretireve problem

Diez B. Roggisch deetsNOSPAM at web.de
Wed Mar 30 15:43:43 EST 2005


> I'm coding a program for offline package management.
> The link that I provided could be obsolete by newer packages. That is
> where my problem is. I wanted to know how to raise an exception here so
> that depending on the type of exception I could make my program function.
> 
> For example, for Temporary Name Resolution Failure, python raises an
> exception which I've handled well. The problem lies with obsolete urls
> where no exception is raised and I end up having a 404 error page as my
> data.
> 
> Can we have an exception for that ?  Or can we have the exit status of
> urllib.urlretrieve to know if it downloaded the desired file.
> I think my problem is fixable in urllib.urlopen, I just find
> urllib.urlretrieve more convenient and want to know if it can be done with
> it.

It makes no sense having urllib generating exceptions for such a case. From
its point of view, things work pefectly - it got a result. No network error
or whatsoever.

Its your application that is not happy with the result - but it has to
figure that out by itself. 

You could for instance try and see what kind of result you got using the
unix file command - it will tell you that you received a html file, not a
deb.

Or check the mimetype returned - its text/html in the error case of yours,
and most probably something like application/octet-stream otherwise.

Regards,

Diez




More information about the Python-list mailing list