0

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!

0

2 Answers 2

0

Try the following code.

import json

with open('birdw3l2.json') as data_file:    
    data = json.load(data_file).decode('utf-8')
print(data)
Sign up to request clarification or add additional context in comments.

5 Comments

doesn't change a thing :(
no it's always the same problem. Actually even i don't do print, the error still remains...
Actually your file contains some special characters. If its a small file, write it again
or write a program to first remove that special character
well its a quite large data file
0

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.

1 Comment

python 3.x no longer has encoding=: docs.python.org/3/library/json.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.