<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python 3 files_download JPEG. Get UnicodeDecodeError in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-3-files-download-JPEG-Get-UnicodeDecodeError/m-p/501314#M24840</link>
    <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Successful download code:&lt;/P&gt;
&lt;PRE&gt;dbx = dropbox.Dropbox(os.environ[&lt;SPAN&gt;'DROPBOX_TOKEN'&lt;/SPAN&gt;])&lt;BR /&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;entry &lt;SPAN&gt;in &lt;/SPAN&gt;dbx.files_list_folder(&lt;SPAN&gt;''&lt;/SPAN&gt;).entries:&lt;BR /&gt;    md&lt;SPAN&gt;, &lt;/SPAN&gt;response = dbx.files_download(&lt;SPAN&gt;'/' &lt;/SPAN&gt;+ entry.name)&lt;BR /&gt;&lt;BR /&gt;    file_stream = response.content&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;len&lt;/SPAN&gt;(file_stream)&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'bytes; md:'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;md)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code to open file_stream that results in error:&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;with &lt;/SPAN&gt;&lt;SPAN&gt;open&lt;/SPAN&gt;(file_stream&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'rb'&lt;/SPAN&gt;) &lt;SPAN&gt;as &lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;:&lt;BR /&gt;    &lt;SPAN&gt;# do things with file&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same error resulting from Pillow code:&lt;/P&gt;
&lt;PRE&gt;image = Image.open(file_stream)&lt;BR /&gt;image.show()&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks&lt;/P&gt;</description>
    <pubDate>Wed, 03 Mar 2021 11:00:58 GMT</pubDate>
    <dc:creator>katec3</dc:creator>
    <dc:date>2021-03-03T11:00:58Z</dc:date>
    <item>
      <title>Python 3 files_download JPEG. Get UnicodeDecodeError</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-3-files-download-JPEG-Get-UnicodeDecodeError/m-p/501314#M24840</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Successful download code:&lt;/P&gt;
&lt;PRE&gt;dbx = dropbox.Dropbox(os.environ[&lt;SPAN&gt;'DROPBOX_TOKEN'&lt;/SPAN&gt;])&lt;BR /&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;entry &lt;SPAN&gt;in &lt;/SPAN&gt;dbx.files_list_folder(&lt;SPAN&gt;''&lt;/SPAN&gt;).entries:&lt;BR /&gt;    md&lt;SPAN&gt;, &lt;/SPAN&gt;response = dbx.files_download(&lt;SPAN&gt;'/' &lt;/SPAN&gt;+ entry.name)&lt;BR /&gt;&lt;BR /&gt;    file_stream = response.content&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;len&lt;/SPAN&gt;(file_stream)&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'bytes; md:'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;md)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code to open file_stream that results in error:&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;with &lt;/SPAN&gt;&lt;SPAN&gt;open&lt;/SPAN&gt;(file_stream&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'rb'&lt;/SPAN&gt;) &lt;SPAN&gt;as &lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;:&lt;BR /&gt;    &lt;SPAN&gt;# do things with file&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same error resulting from Pillow code:&lt;/P&gt;
&lt;PRE&gt;image = Image.open(file_stream)&lt;BR /&gt;image.show()&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 11:00:58 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-3-files-download-JPEG-Get-UnicodeDecodeError/m-p/501314#M24840</guid>
      <dc:creator>katec3</dc:creator>
      <dc:date>2021-03-03T11:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python 3 files_download JPEG. Get UnicodeDecodeError</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-3-files-download-JPEG-Get-UnicodeDecodeError/m-p/501460#M24843</link>
      <description>&lt;P&gt;&lt;A href="https://docs.python.org/3/library/functions.html#open" target="_self"&gt;The Python open method&lt;/A&gt; expects a &lt;A href="https://docs.python.org/3/glossary.html#term-path-like-object" target="_self"&gt;path-like object&lt;/A&gt;&amp;nbsp;in order to open a file, but your&amp;nbsp;file_stream is the&amp;nbsp;response.content, which is already the actual file data, not a path-like object. You can use it directly without calling open.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for using Pillow, I can't offer help for that as it's not made by Dropbox, but it looks like there's &lt;A href="https://2.python-requests.org/en/master/user/quickstart/#binary-response-content" target="_self"&gt;an example in the requests documentation&lt;/A&gt; that may be helpful here.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 16:12:14 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-3-files-download-JPEG-Get-UnicodeDecodeError/m-p/501460#M24843</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-03-03T16:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python 3 files_download JPEG. Get UnicodeDecodeError</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-3-files-download-JPEG-Get-UnicodeDecodeError/m-p/501691#M24845</link>
      <description>&lt;P&gt;Thank you very much Greg, the link you sent solved it!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 07:42:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-3-files-download-JPEG-Get-UnicodeDecodeError/m-p/501691#M24845</guid>
      <dc:creator>katec3</dc:creator>
      <dc:date>2021-03-04T07:42:06Z</dc:date>
    </item>
  </channel>
</rss>

