0
votes

I want to open a json file in python and I have the error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 64864: ordinal not in range(128)

my code is quite simple:

# -*- coding: utf-8 -*-

import json

with open('birdw3l2.json') as data_file:    
    data = json.load(data_file)
print(data)

Someone can help me? Thanks!

2

2 Answers

0
votes

Try the following code.

import json

with open('birdw3l2.json') as data_file:    
    data = json.load(data_file).decode('utf-8')
print(data)
0
votes

You should specify your encoding format when you load your json file. like this:

 data = json.load(data_file, encoding='utf-8')

The encoding depends on your file encoding.