To solve UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte follow any of the below methods.
Contents
Error log
Traceback (most recent call last):
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 2: invalid start byte
How to solve UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte ?
Follow the below solutions as per the requirement.
If you are using read_csv() the use the below code snippet.
import pandas as pd
data = pd.read_csv(file_name, encoding= 'unicode_escape')
If you are reading a file using with open(file_name,mode)
then use:
with open(path, 'rb') as f:
text = f.read()
The issue occurs because the dictionary contains a non-ascii character that cannot be encoded or decoded. To avoid this error, encode such strings with the encode() function as follows (if an is a string containing a non-ascii character):
file.encode('utf-8').strip()
Hope the above solutions works.
Also read :Animated: `useNativeDriver` was not specified issue of ReactNativeBase Input