I'm using the following code to retrieve an image online:
import Image
import urllib2
import cStringIO
url = 'http://storage.googleapis.com/bloomsky-img/k65x5Kvpyc3W08jBqJ1kqZqnnZapoQ==.jpg'
img = urllib2.urlopen(url).read()
# error occurred when executing the line below
im = Image.open(cStringIO.StringIO(img))
im.verify()
# must reload the image after verify method !!
im = Image.open(cStringIO.StringIO(img))
im.save('name', 'JPEG')
When run, it gives me image not valid and error code is cannot identify image file <StringIO.StringIO instance at 0x7f6825b12e18>
error. But the same code works perfect on my mac. Only when I deployed the code to an Ubuntu server, did I encounter such issue. I checked the documentations and I think I'm using StringIO
in the correct way. Can anybody help? Thanks a lot.