mu icon indicating copy to clipboard operation
mu copied to clipboard

UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 64: illegal multibyte sequence

Open shaohaiyang opened this issue 2 years ago • 5 comments

What were you trying to do?

bug fixed

What steps did you take to trigger the issue?

renamed filename with unicode or gbk.

What did you expect to happen?

open filename with encoding utf-8

What actually happened?

''' with open(path,encoding="utf-8") as f: '''

Operating System Version

windows10

Mu Version

1.1.0b7

Other Info

with open(path,encoding="utf-8") as f:

Editor Log

File "C:\Users\Administrator\AppData\Local\python\mu\mu_venv-38-20220121-141938\lib\site-packages\pgzero\runner.py", line 77, in main src = f.read() UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 64: illegal multibyte sequence

shaohaiyang avatar Jan 22 '22 02:01 shaohaiyang

Hi @shaohaiyang,

Thanks for the report!

File "C:\Users\Administrator\AppData\Local\python\mu\mu_venv-38-20220121-141938\lib\site-packages\pgzero\runner.py", line 77, in main
src = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 64: illegal multibyte sequence

Where did you get that error? and what steps did you take to trigger it? Could you attach a copy of the file? If the file you are trying to run is not 'utf-8' encoded you need to specify the right encoding as a shebang: https://stackoverflow.com/a/729016

carlosperate avatar Jan 24 '22 10:01 carlosperate

Hi @shaohaiyang, were you able to resolve this issue? Was it the code file encoding?

carlosperate avatar May 31 '22 19:05 carlosperate

I got a similar error as @shaohaiyang shared. Here's how I got the error. I have a python script simply prints out some text. But instead of printing it out in the windows prompt. I redirect rhe output to a .txt file python fetch_online_text.py > sample.txt. Then when I try to read the .txt file with python again. I get that error.

ldu2 avatar Jan 26 '24 23:01 ldu2

I would guess that the encoding of the sample.txt file depends on your terminal, so the first step would be to figure out your terminal text encoding, and then on your python script when trying to open the sample.txt file you can pass the encoding type using the encoding arguments in the open function: https://docs.python.org/3/library/functions.html#open

carlosperate avatar Jan 27 '24 15:01 carlosperate

I would guess that the encoding of the sample.txt file depends on your terminal, so the first step would be to figure out your terminal text encoding, and then on your python script when trying to open the sample.txt file you can pass the encoding type using the encoding arguments in the open function: https://docs.python.org/3/library/functions.html#open

You are absolutely right! I tried the steps with a different terminal and the encoding shows different in the editor. Thank you very much!

ldu2 avatar Jan 27 '24 16:01 ldu2