UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>
The file in question is not using the CP1252
encoding. It's using another encoding. Which one you have to figure out yourself. Common ones are Latin-1
and UTF-8
. Since 0x90 doesn't actually mean anything in Latin-1
, UTF-8
(where 0x90 is a continuation byte) is more likely.
You specify the encoding when you open the file:
file = open(filename, encoding="utf8")
#'charmap' codec can't decode byte 0x8d in position 1148
When you use open()
, you also use a default encoding. It most likely didn't fit you. Try using something like -with open(os.path.join(path,item),"r",encoding='utf8')
Or, if you can, check what is the enryption which was used on this file.
Try to check the answers this post, one of them might help you.
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2433: character maps to <undefined>
Just add encoding='utf-8'
within .read_text()
:
paragraph = Path('myfile.txt').read_text(encoding='utf-8')
Json UnicodeDecodeError 'charmap' codec can't decode byte 0x8d in position 3621: character maps to <undefined>
Try
with open('D:\soccer\statsbomb360\matches.json', encoding="utf8") as f:
data = json.load(f)
per @mark-tolonen
Also see this post: UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>
Related Topics
How Does Assignment Work With List Slices
Remove All Occurrences of a Value from a List
Create a Single Executable from a Python Project
Pandas: How to Easily Share a Sample Dataframe Using Df.To_Dict()
Converting Between Datetime, Timestamp and Datetime64
List Comprehension Vs. Lambda + Filter
Convert Dataframe Column Type from String to Datetime
What Causes My Function to Return None At the End
How to Get the Path and Name of the File That Is Currently Executing
Installing Pip Is Not Working in Python ≪ 3.6
Why Can't I Iterate Twice Over the Same Data
How to Convert All Strings in a List of Lists to Integers
How to Get Time of a Python Program'S Execution
How to Write the Fibonacci Sequence
How to Resize an Image Using Pil and Maintain Its Aspect Ratio
How to Initialize a Dictionary of Distinct Empty Lists in Python