Hi Anushree,
I tried the Translator API, and it worked fine for me. The documentation I used is:
https://free.blessedness.top/en-us/azure/ai-services/translator/text-translation/quickstart/rest-api?tabs=python#translate-text
Below is the code. Please paste your API key and try running it to ensure that your resource is working correctly:
import requests, uuid, json
key = "<API-KEY>"
endpoint = "https://api.cognitive.microsofttranslator.com"
location = "eastus"
path = '/translate'
constructed_url = endpoint + path
params = {
'api-version': '3.0',
'from': 'en',
'to': ['fr', 'zu']
}
headers = {
'Ocp-Apim-Subscription-Key': key,
'Ocp-Apim-Subscription-Region': location,
'Content-type': 'application/json',
'X-ClientTraceId': str(uuid.uuid4())
}
body = [{
'text': 'I would really like to drive your car around the block a few times!'
}]
request = requests.post(constructed_url, params=params, headers=headers, json=body)
response = request.json()
print(json.dumps(response, sort_keys=True, ensure_ascii=False, indent=4, separators=(',', ': ')))
Apart from the API key, please also verify:
Request headers
Region
Feel free to accept it as an answer.
Thankyou for reaching out to the Microsoft QNA Portal.