This article can help you learn how to solve the UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x92 in position in Python. Let’s follow this article to learn more about it with the explanation and examples below.
How does the UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x92 in position In Python happen?
The error occurs when you assign the wrong encoding while you are decoding the bytes object.
Look at the example below to learn more about this error.
byte = 'LearnShareIT ’ crvt4722'.encode('cp1252') str = byte.decode('utf-8') # The Error will occur here print(str)
Output
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 13: invalid start byte.
How to solve this error?
These are some solutions that can help you solve the error. You have to set the same encoding which is used to encode the string while you are decoding the bytes object. You can also ignore the error to fix the problem. Another solution is using the encoding =”ISO-8859-1”.
Set the same encoding
You have to set the same encoding which is used to encode the string while you are decoding the bytes object.
Look at the example below to learn more about this solution.
byte = 'LearnShareIT ’ crvt4722'.encode('cp1252') str = byte.decode('cp1252') print(str)
Output
LearnShareIT ’ crvt4722
Ignore the error
If the error occurs, you ignore the characters that can not be decoded by the error keyword.
Look at the example below to learn more about this solution.
with open(file_path,encoding= 'utf-8', errors= 'ignore') as f:
content = f.readlines()
print(content)
Use the encoding = “ISO-8859-1”
You can use the encoding ISO-8859-1 to solve the error.
Look at the example below to learn more about this solution.
with open(file_path,encoding= 'ISO-8859-1') as f:
content = f.readlines()
print(content)
Summary
These are some solutions that can help you solve the UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x92 in position in Python. To solve this problem, you have to set the same encoding which is used to encode the string while you are decoding the bytes object. You can ignore the error or use the encoding ISO-8859-1. Choose the solution that is the most suitable for you. We hope this tutorial is helpful to you. Thanks!
Maybe you are interested:
- “unicodedecodeerror: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte”
- UnicodeDecodeError: ‘charmap’ codec can’t decode byte
- UnicodeDecodeError: ‘utf-8’ codec can’t decode byte in position: invalid continuation byte

My name is Thomas Valen. As a software developer, I am well-versed in programming languages. Don’t worry if you’re having trouble with the C, C++, Java, Python, JavaScript, or R programming languages. I’m here to assist you!
Name of the university: PTIT
Major: IT
Programming Languages: C, C++, Java, Python, JavaScript, R