[Solved] UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xbf in position 7: invalid start byte

Code that gives the error:

f = csv.reader(open(csvroot, 'r',encoding='utf-8'))
for i in f:
    print(i)

Solution for UnicodeDecodeError : Check the format of the file which is used for the encoding

import chardet

f = open(full_csvroot, 'rb')
data = f.read()
print(chardet.detect(data))

# Outcome:
# {'encoding': 'GB2312', 'confidence': 0.99, 'language': 'Chinese'}

Check Out this code too:

f = csv.reader(open(csvroot, 'r',encoding='GB2312'))
for i in f:
    print(i)

Also Read | [Solved]Vue Project Error: Error from chokidar

Ranjeet Singh Rawat
Ranjeet Singh Rawat

Leave a Reply

Your email address will not be published.

three × two =