2017-04-07 6 views
0

다음 http.client 요청 코드를 Requests 라이브러리 양식으로 변환하고 싶습니다.Requests 라이브러리 양식에서 다음 http.client 요청을 어떻게 변환해야합니까? [파이썬]

나는이 작업을 시도했지만 몸체와 머리글 모두가 requests.post(url, data=None, json=None, **kwargs)에 전달 될 것이라고 생각했습니다. 주로 비동기로 만들고 싶기 때문에 요청 라이브러리를 사용해야합니다.

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

감사합니다.

답변

0

body은 실제로 페이로드이기 때문에 data 매개 변수로 전달됩니다.

헤더는 단순히 헤더로 전달됩니다.

r = requests.post(url='http:/speech.platform.bing.com/synthesize', 
        data=body, 
        headers=headers)