我使用以下请求:
headers = {
'Authorization': f'Bearer {self.__yandex_cloud_manager.get_iam_token().token}',
'Transfer-Encoding': 'chunked',
}
data = {
'voice': self.voice,
'emotion': 'neutral',
'lang': self.language,
'speed': self.temp,
'folderId': self.__get_folder_id(),
'format': 'oggopus',
'text': text,
}
response = requests.post(
url='https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize',
headers=headers,
data=data)
它发送此数据:
send: b'POST /speech/v1/tts:synthesize HTTP/1.1\r\nHost: tts.api.cloud.yandex.net\r\nUser-Agent: python-requests/2.21.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Bearer <removed>\r\nTransfer-Encoding: chunked\r\nContent-Length: 135\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'
send: b'voice=alyss&emotion=neutral&lang=ru-RU&speed=1.0&folderId=<removed>&format=oggopus&text=%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82'
我得到400条回复。
但是当我这样转储请求时:
req = response.request
command = "curl -X {method} -H {headers} -d '{data}' '{uri}'"
method = req.method
uri = req.url
data = req.body
headers = ['"{0}: {1}"'.format(k, v) for k, v in req.headers.items()]
headers = " -H ".join(headers)
print(command.format(method=method, headers=headers, data=data, uri=uri))
它给出以下命令:
curl -X POST -H "User-Agent: python-requests/2.21.0" -H "Accept-Encoding: gzip, deflate" -H "Accept: */*" -H "Connection: keep-alive" -H "Authorization: Bearer <removed>" -H "Transfer-Encoding: chunked" -H "Content-Length: 135" -H "Content-Type: application/x-www-form-urlencoded" -d 'voice=alyss&emotion=neutral&lang=ru-RU&speed=1.0&folderId=<removed>&format=oggopus&text=%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82' 'https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize'
并且此命令的请求成功执行。
可能会发生什么?
答案 0 :(得分:0)
好吧,如果我删除"Transfer-Encoding: chunked"
标头,它就可以工作。