我的代码:
def saveJSONget(site, code):
response = requests.get(site)
json_str = json.dumps(response.json())
if not response.status_code == code:
file = open("PATH", 'w')
file.write(str(response.text) + "\n")
我需要保存文件json所有信息:标头响应和请求,请求有效负载。我不知道使用什么函数,写入文件这个元素。我有第二个问题。
如何改变我的方法? 错误:
Error
Traceback (most recent call last):
File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/lib/python3.6/unittest/case.py", line 601, in run
self.setUp()
File "PATH", line 13, in setUp
Class.method(site, 210)
File "PATHy", line 171, in method
json_str = json.dumps(response.json())
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/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)
谢谢你的帮助
答案 0 :(得分:0)
List<SwitchListTiles>