0

I'm struggling to upload files to Dropbox via Python using their module. The error is always the following:

UnicodeEncodeError: 'latin-1' codec can't encode character '\u200b' in position 71: ordinal not in range(256)

Originally, I thought it was an encoding error with the CSV I was trying to upload, so I tried replacing any '\u200b' (zero-width space) with a normal space in my CSV, but I still got the same error. I changed the encoding settings when I went to write the CSV-- same error. I even tried going into the code file that was generating the error and changing it's encoding to 'utf-8' and I just got an error from having changed it (I set it back to normal).

So I'm really flummoxed on this error. Maybe you guys can enlighten me. I've been able to generate this error in a really simple context in a way that's practically identical to what I'm using.

Here's the CSV that I'm trying to upload (file.csv):

a,b,c
d,e,f

And here is my code that throws the error:

import dropbox

dbx = dropbox.dropbox.Dropbox('my_token')

with open('file.csv', 'rb') as f:
    dbx.files_upload(f.read(), '/path/to/file.csv', mode=dropbox.files.WriteMode.overwrite)

I've been trying to follow the documentation to a T and as far as I can tell, I am...? Here is a link to the documentation if that's helpful.

Anything you guys can do to even push me in the right direction would be appreciated.

  • 1
    Are you sure that the error is in the file? You've already loaded that as a binary file, so it shouldn't have to be encoded... Make sure that the error isn't coming from the path to the file. – Roland Smith Jan 04 '19 at 18:55
  • @RolandSmith That actually makes a lot of sense. How would I be able to tell if different directories have the zero-width space in them? Is that something I need to do pythonically or can I just do it with Windows? – Matt Youngberg Jan 04 '19 at 19:12
  • 1
    Well, you wouldn't *see* a zero-width space. So checking with Python is probably the best way. But copying the string into a hex editor would also work. – Roland Smith Jan 04 '19 at 19:25
  • Possibly helpful [SuperUser: How to find files with non-ascii characteers in filenames in Windows XP](https://superuser.com/questions/237533/find-files-with-non-ascii-characters-in-filenames-in-windows-xp) – snakecharmerb Jan 05 '19 at 10:27
  • Thanks so much, @RolandSmith! I found a zero-width space in my filepath. It's all fixed now! – Matt Youngberg Jan 07 '19 at 14:48

0 Answers0