0

I want to convert the following http.client request code to Requests Library form.

I tried doing this, but was stuck thinking where would body and header both be passed in requests.post(url, data=None, json=None, **kwargs). I need to use requests library, mainly because I want to make it asynchronous.

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()

Thanks!!

Sameer Kumar
  • 93
  • 3
  • 10

1 Answers1

0

Your body, is really just payload, so that will be passed as the data parameter.

Headers are simply passed as, um, headers.

r = requests.post(url='http:/speech.platform.bing.com/synthesize',
                  data=body,
                  headers=headers)
pbuck
  • 4,291
  • 2
  • 24
  • 36