【发布时间】:2019-12-08 06:36:06
【问题描述】:
我正在尝试运行具有多个 id 的 API,并且正在规范化 json 文件并尝试将其放入数据帧中。使用我当前的代码,我只能得到一个对 jsonfile2 的响应。当我尝试打印 json 响应时,我会得到所有响应,但 response.json() 在我的代码中不起作用。
for id in ids:
time.sleep(1)
url = "https:url/../details/"+str(id)
querystring = {"API-Token":"Token"}
headers = {
'cache-control': "no-cache",
'postman-token': "111111111111111111111"
}
response = requests.request("GET", url.format(id=ids), headers=headers, params=querystring)
# print(response.json())
jsonfile2 = response.json()
works_data2 = json_normalize(jsonfile2, record_path='result')
JSON 响应示例
{
"result": {
"id": "string",
"startTime": 0,
"endTime": 0,
"tags": [
{
"context": "context",
}
],
"Events": [
{
"startTime": 0,
"endTime": 0,
"entityId": "string",
"status": "CLOSED",
"severities": [
{
"context": "context",
"value": 0,
"unit": "Bit (bit)"
}
]
}
}
【问题讨论】: