azure synapse笔记本请求认知服务转换器

odopli94  于 2021-07-14  发布在  Spark
关注(0)|答案(0)|浏览(228)

我在azure synapse中有一个笔记本,我使用azure认知服务来翻译数据。代码以前是可以工作的,但我必须通过synapse工作区重新构建,它不再工作了。看起来spark环境无法访问internet或其他azure服务,因为我刚刚收到连接超时。我不知道如何配置访问,因为我用托管vlan配置了synapse。

import os, requests, uuid, json
subscription_key = "XXXXXXXXXXXXXXXXXXXXXXXXXX"
constructed_url = "https://api-eur.cognitive.microsofttranslator.com/translate?api- 
  version=3.0&from=en&to=af"
headers = {
  'Ocp-Apim-Subscription-Key': subscription_key,
  'Ocp-Apim-Subscription-Region' : 'northeurope',
  'Content-type': 'application/json',
  'X-ClientTraceId': str(uuid.uuid4())
}
body = [{
  'text' : 'hello'
}]
request = requests.post(constructed_url, headers=headers, json=body)
response = request.json()
print(json.dumps(response, sort_keys=True, indent=4, separators=(',', ': ')))

结果:
connecttimeout:httpsconnectionpool(host='api-eur.cognitive.microsofttranslator.com',port=443):url:/translate?api version=3.0&from=en&to=af超过最大重试次数(由connecttimeouterror(<urllib3.connection.httpsconnection object at 0x7f83aa63fc18>,'到api-eur.cognitive.microsofttranslator.com的连接超时引起)(连接超时=10秒)
我已经为认知服务配置了一个私有端点,但这没有帮助。有什么想法吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题