1

When I run my Python file I get the following error:

config = open('config.json', 'r')
config_data = json.load(config_file)

This is my json file:

{
 "temp_unit": "celsius"
}

I get the following error:

Traceback (most recent call last):
  File "/home/paul/Documents/Nouvale/main.py", line 90, in <module>
    App.read_config()
  File "/home/paul/Documents/Nouvale/main.py", line 35, in read_config
    config_data = json.load(config_file)
  File "/usr/lib/python3.10/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Does anyone know how I can fix this? I am using Zorin 16.1 Pro, Python 3.8.10 & Pip 20.0.2.

1 Answer 1

1

Soloution


To fix the error I added an encoding parameter.


config = open('config.json', 'r', encoding='utf-8')
config_data = json.load(config)
Sign up to request clarification or add additional context in comments.

Comments

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.