Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Weird Unicode error

Nilats (3750 points)
8 14 29
in HW6 by (3.8k points)

I get this weird error when I try to open the file "example.txt"

"UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 5862: invalid continuation byte"

there are only numbers and commas inside the file.

618 views
closed

5 Answers

Best answer
GabrielAlexandru (7760 points)
2 4 29
by (7.8k points)
selected by
People in the Italian course had the same problem. In their case it was related to the fact that they were using the .ita.py file. When they switched to the .eng.py everything worked fine.

I don’t know if this applies to you too, but you can try!
andrea.sterbini (207920 points)
750 1267 2373
by (208k points)

Have you tried to add the following line at the top of the file?

# -*- coding: utf-8 -*-

Nilats (3750 points)
8 14 29
by (3.8k points)
Yeah, I just copy-pasted the whole code to the English file and now it's working.
n
nane.harutyunyan (790 points)
0 0 4
by (790 points)

I am not very sure that it has anything to do with this, but maybe try to specify the encoding explicitly when opening the file (in case you haven't done so); pass encoding="utf-8" in the opening function.

Nilats (3750 points)
8 14 29
by (3.8k points)
I've already done it.
I also tried encoding="latin-1"
rokshana03 (16750 points)
1 4 35
by (16.8k points)
So, I tried to do some research about this. In most of the cases, they say to change the encoding to "latin-1" but it doesn't work for you.

You could try with encoding ='ISO-8859-1' or by opening it in "rb" so in binary mode. ( this is what internet sources say)                                                                                                                  

Although, I'm wondering how you got that error. The file itself is encoded in utf-8, I opened it just fine. i doubt that its encoded in another format. Did you remove the spaces before opening it? Perhaps, something you did modified the encoding of the file?
Nilats (3750 points)
8 14 29
by (3.8k points)
I already tried those as well and nope, it's not working.
gianluca5539 (9820 points)
4 6 44
by (9.8k points)
try to open a new example.txt file without opening it with your OS, just open it with the code. Your text editor could have corrupted the file.
Quellocinese (2700 points)
4 4 22
by (2.7k points)
just comment or delete all the instructions given in the program01 file at the beginning