Задача получить json из веба и записать результат в report.json. В папке два файла: test2.py и report.json(пустой).
Код:
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)
Результат:
/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