0

Saw other threads for this and the common solution is to explicitly specify an encoder (UTF-8) when opening/writing the file. Another is to ignore errors. I've tried both but it stil didn't work.

  • We have no idea what's in the file and thus cannot tell what would be the correct solution. Please [edit] your question to provide more details; see also https://meta.stackoverflow.com/questions/379403/problematic-questions-about-decoding-errors – tripleee Jul 11 '19 at 11:19

1 Answers1

0

The file shoud contain something else than text encoded in UTF-8 or latin1 as 0x9d alone is not valid UTF-8, nor latin1.

But it can be many many other encodings. For example it could be CP861, in which case it's a Ø. But I took CP861 randomly, it can be any other encoding that have a meaning for 0x9d.

It can also be an error in your file, or a file containing something else than text (in which it would have failed before position 5697 I bet).

If you don't mind giving us more information, it could help, maybe:

with open(source, "rb") as from_A:
    print(from_A.read()[5697-10, 5697+10])

Also, if you don't really need the content of the file, you can just skip decoding and re-encoding it by using the b flag of open:

with open(source, mode='rb') as from_A, open(destination, mode='wb') as to_A:

And if you're just trying to copy the file you can just use shutil:

shutil.copyfile(source, destination)
Julien Palard
  • 8,736
  • 2
  • 37
  • 44