Skip to main content
added 128 characters in body
Source Link
Raphael Medaer
  • 2.5k
  • 14
  • 19

It's difficult to debug without the preferred encoding of your system. You can get it with:

import locale
locale.getpreferredencoding(False)

But I suspect that your encoding is not ASCII or UTF8. Since Python3, open takes an argument encoding. You couldshould try to specify thisthe encoding utf-8.

import json

with open('example.json', 'r', encoding='utf-8') as f:
    print(json.loads(f.read()))

It's difficult to debug without the preferred encoding of your system. You can get it with:

import locale
locale.getpreferredencoding(False)

But I suspect that your encoding is not ASCII or UTF8. Since Python3, open takes an argument encoding. You could try to specify this encoding.

It's difficult to debug without the preferred encoding of your system. You can get it with:

import locale
locale.getpreferredencoding(False)

But I suspect that your encoding is not ASCII or UTF8. Since Python3, open takes an argument encoding. You should try to specify the encoding utf-8.

import json

with open('example.json', 'r', encoding='utf-8') as f:
    print(json.loads(f.read()))
Remove out-of-scope reference to json.loads (see https://github.com/python/cpython/blob/master/Lib/json/__init__.py#L293)
Source Link
Raphael Medaer
  • 2.5k
  • 14
  • 19

It's difficult to debug without the preferred encoding of your system. You can get it with:

import locale
locale.getpreferredencoding(False)

But I suspect that your encoding is not ASCII or UTF8. Since Python3, open takes an argument encoding. You could try to specify this encoding.

Btw json module has also a method load (without s) which takes as first argument fp:

Deserialize fp (a .read()-supporting text file or binary file containing a JSON document) (...)

You could use it instead of loads (with a s).

It's difficult to debug without the preferred encoding of your system. You can get it with:

import locale
locale.getpreferredencoding(False)

But I suspect that your encoding is not ASCII or UTF8. Since Python3, open takes an argument encoding. You could try to specify this encoding.

Btw json module has also a method load (without s) which takes as first argument fp:

Deserialize fp (a .read()-supporting text file or binary file containing a JSON document) (...)

You could use it instead of loads (with a s).

It's difficult to debug without the preferred encoding of your system. You can get it with:

import locale
locale.getpreferredencoding(False)

But I suspect that your encoding is not ASCII or UTF8. Since Python3, open takes an argument encoding. You could try to specify this encoding.

Source Link
Raphael Medaer
  • 2.5k
  • 14
  • 19

It's difficult to debug without the preferred encoding of your system. You can get it with:

import locale
locale.getpreferredencoding(False)

But I suspect that your encoding is not ASCII or UTF8. Since Python3, open takes an argument encoding. You could try to specify this encoding.

Btw json module has also a method load (without s) which takes as first argument fp:

Deserialize fp (a .read()-supporting text file or binary file containing a JSON document) (...)

You could use it instead of loads (with a s).