0

I'm trying to automate uploading receipt pdfs to google drive, but I'm running into trouble just uploading the pdf in question.

'''ALREADY IMPORTED AND AUTHENTICATED'''
os.chdir('C:\\Users\\sophi\\.spyder-py3-dev\\FishtagScripts')
for file in glob.glob("*.pdf"):
    print(file)
    with open(file,"r") as f:
        fn = os.path.basename(f.name)
        file_drive = drive.CreateFile({'title': fn })  
        file_drive.SetContentString(f.read()) 
        file_drive.Upload()

I expected the pdf to be uploaded to My Drive, but instead it throws the error message UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 762: character maps to

  • 1
    try with `open(file,"rb")` so that it reads bytes and than try decoding them with utf8 – PMM Aug 09 '19 at 20:29
  • @PietroMarsella When I tried that, I got another UnicodeDecodeError:'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte – Sophia Ribeiro Aug 10 '19 at 02:53

0 Answers0