Unable to call cognitive service text translator

Category: azure analysis services


hinda32 on Mon, 19 Jun 2017 10:18:09

I am trying to call microsoft cognitive services translator with python using the following code: but i get errors, any idea why

from xml.etree import ElementTree
#from auth import AzureAuthClient
import requests

fromLangCode = "en"
toLangCode = "es"
textToTranslate = df #df is a data frame of text elements

# Call to Microsoft Translator Service

headers = {"Authorization ": 'zzzzzzzzzzzzzzzz'}
#translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?   text={}&to={}".format(textToTranslate, toLangCode)
translateUrl = "https://api.cognitive.microsoft.com/sts/v1.0".format   (textToTranslate, toLangCode)
translationData = requests.get(translateUrl, headers = headers)
# parse xml return values
translation = ElementTree.fromstring(translationData.text.encode('utf-8')) 

I get an error File "", line unknown ParseError: not well-formed (invalid token)