Reputation: 443
I'm writing a script to download a Steam profile picture from its URL, as provided by the Steam API. Regardless of the method that I use, I'm getting corrupted results:
Steam's link to the original image.
Using the "requests" library:
avatar = open(avatarName, 'wb')
avatar.write(requests.get(avatarURL).content)
avatar.close()
as well as:
avatar = requests.get(avatarURL)
with open(avatarName, 'wb') as f:
f.write(avatar.content)
And using the "urllib" library:
urllib.urlretrieve(avatarURL, avatarName)
as well as:
avatar = urllib.URLopener()
avatar.retrieve(avatarURL, avatarName)
And using wget directly on the link (note that this is outside Python, just from the terminal):
wget http://media.steampowered.com/steamcommunity/public/images/avatars/ad/adec76ed86e8ffa892d847c8e619262d30e74e32_full.jpg
Since it's a corruption issue I was thinking it might have to do with setting/not setting the binary flag when I open the file object. Another method I haven't tried yet is importing OS commands and using wget to download the file and then working from there. wget gives the corrupted result as well.
Interestingly enough, it appears that every method used results in images that are corrupted in exactly the same way every time.
I haven't used urllib2 yet (here), simply because most of the Q&A's I've been checking have been using urllib.
Upvotes: 1
Views: 1712
Reputation: 443
After @ton1c said everything worked for him, I tried running wget from another system and it worked just fine. I'm using Filezilla to transfer files to/from my server, so I checked the images actually on the server by navigating to them with a browser and all of them rendered normally. Apparently downloading them to my computer with Filezilla caused the corruption. That's a different problem, but a minor one that I'll figure out on my own.
Upvotes: 1