使用python调用microsoft认知服务转换器

2024-09-30 00:40:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在在python3中从azure笔记本中尝试以下代码 导入请求

# Getting the key from tab Keys on Azure portal
 key = "xxxxxxxxxxx" 


 url4authentication = 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken'
 headers4authentication = {'Ocp-Apim-Subscription-Key': key}
 resp4authentication = requests.post(url4authentication,  headers=headers4authentication)
 token = resp4authentication.text

 print(token)
 text="hello there how are you"
 come = "en"
 to = "es"
 url4translate = 'https://api.microsofttranslator.com/v2/http.svc/Translate'
 from xml.etree import ElementTree
 response = requests.get('https://api.microsofttranslator.com/v2/http.svc', params = param)
 print(response)

我得到以下错误:

^{pr2}$

Tags: keytextfromhttpscomtokenapihttp

热门问题