The task is to get json from the web and write the result to report.json. There are two files in the folder: test2.py and report.json (empty).
Code:
import requests import json r = requests.get('https://www.wikidata.org//w/api.php?action=query&format=json&meta=siteinfo&siprop=namespaces') report = r.json() print(report) with open('report.json') as report: data = json.load(report) print(data)
Result:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3 "/Volumes/My Files/Python/iikoBot/test2.py" {'batchcomplete': '','query': {'namespaces': ...тело json... 'case': 'first-letter'}}}} Traceback (most recent call last): File "/Volumes/My Files/Python/iikoBot/test2.py", line 8, in <module> data = json.load(report) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 268, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 319, in loads return _default_decoder.decode(s) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) Process finished with exit code 1