我想将下面的http.client请求代码转换为Requests库形式。
我试过这样做,但被卡住了,想在requests.post(url, data=None, json=None, **kwargs)中把body和header都传递到哪里。我需要使用请求库,主要是因为我想让它异步。
headers = {"Content-type": "application/ssml+xml",
"X-Microsoft-OutputFormat": "audio-16khz-128kbitrate-mono-mp3",
"Authorization": "Bearer " + access_token,
"X-Search-AppId": "__ID__",
"X-Search-ClientID": "__ID__",
"User-Agent": "TTSForPython"}
body = "<speak version='1.0' xml:lang='en-us'><voice xml:lang='en-CA' xml:gender='Female' name='Microsoft Server Speech Text to Speech Voice (en-CA, HeatherRUS)'>" + text + "</voice></speak>"
conn = http.client.HTTPSConnection("speech.platform.bing.com")
conn.request("POST", "/synthesize", body, headers)
response = conn.getresponse()谢谢!!
发布于 2017-04-08 05:20:03
您的body实际上只是一个有效负载,因此它将作为data参数传递。
headers只是作为,嗯,Headers传递。
r = requests.post(url='http:/speech.platform.bing.com/synthesize',
data=body,
headers=headers)https://stackoverflow.com/questions/43287061
复制相似问题