Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

katec3's avatar
katec3
Explorer | Level 3
5 years ago
Solved

Python 3 files_download JPEG. Get UnicodeDecodeError

Using Python 3.8 I can successfully download a JPEG image. However, I want to access the exif information so am trying to use Pillow to open it. Whatever I try I get the following error: 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte'. I'd be grateful for any suggestions as I'm stumped.

 

Successful download code:

dbx = dropbox.Dropbox(os.environ['DROPBOX_TOKEN'])
for entry in dbx.files_list_folder('').entries:
md, response = dbx.files_download('/' + entry.name)

file_stream = response.content
print(len(file_stream), 'bytes; md:', md)

 

Code to open file_stream that results in error:

with open(file_stream, 'rb') as data:
# do things with file

 

Same error resulting from Pillow code:

image = Image.open(file_stream)
image.show()

 

Many thanks

2 Replies

  • katec3's avatar
    katec3
    Explorer | Level 3
    5 years ago

    Thank you very much Greg, the link you sent solved it!

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!