I'm having a problem when I use python to save an image from a URL, either using a urllib2 request or urllib.urlretrieve. That is, the image URL is valid. I can download it manually using explorer. However, when I use python to upload an image, the file cannot be opened. I am using Mac OS preview to view the image. Thanks!
UPDATE:
The code is as follows
def downloadImage(self): request = urllib2.Request(self.url) pic = urllib2.urlopen(request) print "downloading: " + self.url print self.fileName filePath = localSaveRoot + self.catalog + self.fileName + Picture.postfix
The URL of the image I want to download is http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg
This url is valid and I can save it through a browser, but python code will load a file that cannot be opened. The preview says: "It may be corrupted or use a file format that Preview does not recognize." I am comparing an image that I upload using Python and one that I upload manually through a browser. The size of the first is a few bytes smaller. Thus, it seems that the file is not complete, but I do not know why python cannot load it completely.
source share