Read .docx with .read () causes an error in Python

0

I'm trying to upload a file to Dropbox, it produces an error. The code I am using is the following:

import dropbox

dbx = dropbox.Dropbox('mi_codigo_de_dropbox')
nombreArchivo = 'Reporte 49.docx'
path = '/machineAR/' + nombreArchivo
with open(nombreArchivo, 'r') as f:
    dbx.files_upload(f.read(), path)

What happens is that the% .read() module throws me the following error:

'utf-8' codec can't decode bytes in position 10-11: invalid continuation type

I've already tried several types of files, .docx empty and even with .png files and it does not work.

Thank you very much in advance.

    
asked by Daniel López Correa 05.11.2018 в 02:17
source

1 answer

0

The solution was:

import dropbox

dbx = dropbox.Dropbox('mi_codigo_de_dropbox')
nombreArchivo = 'Reporte 49.docx'
path = '/machineAR/' + nombreArchivo
with open(nombreArchivo, 'rb') as f:
    dbx.files_upload(f.read(), path)
    
answered by 05.11.2018 в 05:38