Blankman
Blankman

Reputation: 267140

When download an image, does urllib have a return code if it's successful or not?

I want to download an image file from potentially 5 sites.

Meaning that if the image wasn't found in site#1, try site#2, etc.

How can I test if the file was downloaded?

Upvotes: 1

Views: 172

Answers (1)

John Flatness
John Flatness

Reputation: 33789

You can call getcode() on the object you get back from urlopen().

getcode() gives you the HTTP status response from the server, so you can test to see if you got an HTTP 200 response, which would mean the download was successful.

Upvotes: 3

Related Questions