【发布时间】:2026-02-21 12:35:02
【问题描述】:
我正在尝试发布HTTP 请求。我已经设法让代码工作,但我正在努力返回一些结果。
结果是这样的
{
"requestId" : "8317cgs1e1-36hd42-43h6be-br34r2-c70a6ege3fs5sbh",
"numberOfRequests" : 1893
}
我正在尝试获取 requestId,但我不断收到错误 Response' object is not subscriptable
import json
import requests
workingFile = 'D:\\test.json'
with open(workingFile, 'r') as fh:
data = json.load(fh)
url = 'http://jsontest'
username = 'user'
password = 'password123'
requestpost = requests.post(url, json=data, auth=(username, password))
print(requestpost["requestId"])
【问题讨论】: