Azure Synapse Notebook 对认知服务转换器的请求

问题描述

我在 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=(',',': ')))

结果:

连接超时: HTTPSConnectionPool(host='api-eur.cognitive.microsofttranslator.com',端口 = 443):超过最大重试次数,网址: /translate?api-version=3.0&from=en&to=af(由 ConnectTimeoutError(,'连接到 api-eur.cognitive.microsofttranslator.com 超时。 (连接 超时=10)'))

我已经为认知服务配置了一个私有端点,但这无济于事。有什么想法吗?

解决方法

您的 Synapse 工作区似乎没有任何出站连接(数据泄露保护已开启)。我们仍在从这些工作区启用认知服务集成。目前,它与异常检测器和文本分析的专用端点一起使用。我们正在通过 Translator 调查此问题的根本原因,并在了解更多信息后予以回复。

谢谢, 内莉