我正在尝试同时发送多个带有 JSON 有效负载的 POST 请求并检索 JSON 结果。我已经阅读了其他一些关于 SO 的帖子,但没有任何效果。
def transcribe(vid_segs):
payloads = []
for vid in vid_segs:
vid = base64.b64encode(open(vid).read())
payload = {
"config": {
"encoding": "LINEAR16",
"sampleRateHertz": 16000,
"languageCode": "en-US",
"speechContexts": {
"phrases:": ["Barack", "Obama", "Barack Obama"]
}
},
"audio": {
"content": vid
}
}
payloads.append(payload)
url = "https://speech.googleapis.com/v1/speech:recognize?key=MYAPIKEY"
unsent_request = []
for payload_single in payloads:
unsent_request.append(grequests.get(url,
params=payload_single))
responses = grequests.map(unsent_request)
for response in responses:
print response.json()
response.close()
如果我使用 response.json(),它会返回错误:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
如果我尝试使用 response.json,返回的不是实际的 JSON 内容,只是对象详细信息和响应代码:
<bound method Response.json of <Response [404]>>
有任何想法吗?提前致谢!