I'm trying to simultaneously send multiple POST requests with JSON payloads and retrieve the JSON results. I've read a few other posts on SO but nothing is doing the trick.
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()
If I use response.json(), it returns the error:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
If I try with response.json, what's returned isn't the actual JSON content, just the object details and the response code:
<bound method Response.json of <Response [404]>>
Any ideas? Thanks in advance!