[Solved] UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa5 in position 1508: illegal multibyte sequence

The error contents are as follows:

Python 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 15:37:01) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "D:\Users\Admin\Anaconda3\envs\tff2\lib\site.py", line 439, in register_readline
    readline.read_history_file(history)
  File "D:\Users\Admin\Anaconda3\envs\tff2\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
    self.mode._history.read_history_file(filename)
  File "D:\Users\Admin\Anaconda3\envs\tff2\lib\site-packages\pyreadline\lineeditor\history.py", line 82, in read_history_file
    for line in open(filename, 'r'):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa5 in position 1508: illegal multibyte sequence

Solution:

# Find the history file with the following path.
D:\anaconda3\Lib\site-packages\pyreadline\lineeditor\history.py 
# If the problem is with a particular environment, the path is
D:\anaconda3\envs\**\Lib\site-packages\pyreadline\lineeditor\history.py

# Modify codes
Line 82 
Change   for line in open(filename, 'r'):
to for line in open(filename, 'r', encoding='utf-8'):

Similar Posts: