I want data returned in JSON format instead of XML in the following code, where headers
is the key to the API. requests.get(translateUrl,headers=headers)
gives XML.
headers = {"Authorization ": finalToken}
translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text={}&to={}".format(textToTranslate, toLangCode)
translationData = requests.get(translateUrl, headers = headers)
# parse xml return values
translation = ElementTree.fromstring(translationData.text.encode('utf-8'))
# display translation
print (translation.text)
There is an existing feature request for this.
For now you will have to convert it on the client side. Here is where you might additional info.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.