-2

I use the following code to download the image 14112758275517_800X533.jpg.

The problem is that I cannot open the 14112758275517_800X533.jpg saved as G:\\image.jpg because the Windows photo viewer was unable to open the picture, as the file may be corrupted, damaged or too large

import urllib
imageurl="http://img.vogue.com.cn/userfiles/201409/14112758275517_800X533.jpg"
pic_name = "G:\\image.jpg"
urllib.urlretrieve(imageurl, pic_name)

How can I download the image so that it is readable?

gboffi
  • 22,939
  • 8
  • 54
  • 85
x Lu
  • 31
  • 1
  • 3
  • Well I get a `403 Forbidden` when I try the link so maybe it's a website problem ? – d6bels Mar 04 '15 at 14:08
  • Or it might be forbidding direct access to resources, i.e Hot Link protection. As well you might try to search before posting. See: http://stackoverflow.com/questions/3042757/downloading-a-picture-via-urllib-and-python – DaGhostman Dimitrov Mar 04 '15 at 14:10
  • 1
    Open the downloaded file with a text editor. Odds are you've got a 403 forbidden error message in there. To emulate a browser, you'll need to do a lot of things including setting referrer / user-agent headers. – Basic Mar 04 '15 at 14:15

1 Answers1

0

I think you cannot. It is likely a website problem, not something in the code you posted.
I am given a 403 Forbidden when trying to type the url you gave even with a navigator.

As an example, the following works and only the url has changed :

import urllib
imageurl="https://www.python.org/static/img/python-logo.png"
pic_name = "./image.png"
urllib.urlretrieve(imageurl, pic_name)

However, you might want to check other topics about the subjet as there are more advanced techniques to download images from the web such as https://stackoverflow.com/a/8389368/2549230

Community
  • 1
  • 1
d6bels
  • 1,432
  • 2
  • 18
  • 30
  • I think you are being rep-hound (not to be offensive, by saying the other name for it) as you can see from my comment, the one from@Peter and the one you, yourself have linked to this question is obviously a duplicate. – DaGhostman Dimitrov Mar 04 '15 at 14:25
  • I see what you mean but I have already commented, flagged and downvoted the question, so you think I shouldn't have answered it then? I think as long as the question has not been deleted *yet*, the OP may deserve an answer. – d6bels Mar 04 '15 at 14:31
  • I think that commenting with a link to a similar(same?) question is enough and the question should be flagged/cv. PS: `Sorry if I sounded offensive, I did not meant to` – DaGhostman Dimitrov Mar 04 '15 at 14:37
  • Plus, even though marked as duplicate, no one as yet proven to download the image using other techniques and they might not even help the OP in that particular case. There's no need to apologize for discussing and giving your opinion, there's no problem about it, that's what comments are for ;) – d6bels Mar 04 '15 at 14:38
  • Honestly, when you hit the URL in the browser you get redirected to a white pixel image on the `www` sub-domain of that site. So I'm guessing that the reason might be Hot Link protection or in other words, they don't want to have their images downloaded :D – DaGhostman Dimitrov Mar 04 '15 at 14:42
  • I get the 403 but no redirection to a white pixel image. You might be right but from where I am and with my browser it's just a 403. – d6bels Mar 04 '15 at 14:45