UnicodeDecodeError when calling put_photo with an image generated with PIL #43

honi opened this Issue Aug 17, 2012 · 5 comments


None yet
2 participants

honi commented Aug 17, 2012

For some reason, images generated with PIL throw a UnicodeDecodeError when trying to upload to Facebook.

Tested opening the image in Photoshop and saved as a new copy, and that image uploaded fine.


martey commented Aug 17, 2012

Would it be possible for you to provide an image that is causing this error? This would help with debugging.

honi commented Aug 17, 2012

Yes, of course: http://imagebin.org/224882. This image was generated with PIL.

I'm also debugging on my side, will post if anything new.

honi commented Aug 17, 2012

I've managed to make it work like this:

image = Image.open('/path/to/image.jpg')
image_io = StringIO()
image.save(image_io, 'jpeg', quality=95)

api = GraphAPI('oauth_token')
api.put_photo(image_io, 'Uploaded image from Facebook SDK')

honi commented Aug 19, 2012

One more thing be careful with.

Everything was working fine, until I added album_id parameter in put_photo. Then I started getting:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 345: ordinal not in range(128)

Turns out my album_id was an int. Just had to cast it to str() when calling put_photo for everything to work.


martey commented Jan 26, 2015

I am pretty sure that this issue has been fixed by moving to requests (which involved significant changes to how put_photo works). Closing.

@martey martey closed this Jan 26, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment