Hello,
I am using pyinstaller to generate exe from py file but i am getting following error:
"
Traceback (most recent call last):
File "c:\users\a\appdata\local\programs\python\python35-32\lib\tokenize.py", line 392, in find_cookie
line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa6 in position 0: invalid start byte
During handling of the above exception, another exception occurred:
"
Please guide
which commando did you use?
Hello
i used
pyinstaller -f
and i also tried on
auto-py-to-exe
Post your code.
(Jul-02-2019, 09:37 AM)vipinv23 Wrote: [ -> ]UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa6 in position 0: invalid start byte
So code try to read something that utf-8 can not decode.
It can be that you should have defined encoding for it or it's just messy from start.
When mean define encoding i mean to us encoding parameter in open():
# Write to disk
ch = '全国政协十三届二次会议在京开幕'
with open('ch.txt', 'w', encoding='utf-8') as f_out:
f_out.write(ch)
# Read from disk
with open('ch.txt', encoding='utf-8') as f:
print(f.read()) # 全国政协十三届二次会议在京开
Some tips for fixing:
# Read from disk
with open('ch.txt', encoding='utf-8', errors='ignore') as f:
print(f.read())
>>> s = b'2018-03-26,HQ Service Center,Handset,Samsung Galaxy S9+ and Charger \xffBlack,1,Sales\r\n'
>>> s.decode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 68: invalid start byte
'utf-8' codec can't decode byte 0xff in position 68: invalid start byte
>>> # Try other codec
>>> s.decode('latin-1')
'2018-03-26,HQ Service Center,Handset,Samsung Galaxy S9+ and Charger ÿBlack,1,Sales\r\n'
>>> # Just ignore error
>>> s.decode('utf-8', errors='ignore')
'2018-03-26,HQ Service Center,Handset,Samsung Galaxy S9+ and Charger Black,1,Sales\r\n'
>>> # Replace with fill in(?) where error is
>>> s.decode('utf-8', errors='replace')
'2018-03-26,HQ Service Center,Handset,Samsung Galaxy S9+ and Charger �Black,1,Sales\r\n'