简体   繁体   中英

Azure Synapse Notebook request to Cognitive services translator

I've got a notebook in Azure Synapse that I use to translate data using Azure Cognitive Services. The code used to work, but I had to rebuild by Synapse workspace and it no longer works. It looks like the Spark environment has no access to the internet or other Azure services, as I just get a connection timeout. I don't know how to configure access, as I configured Synapse with a managed vlan.

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

Result:

ConnectTimeout: HTTPSConnectionPool(host='api-eur.cognitive.microsofttranslator.com', port=443): Max retries exceeded with url: /translate?api-version=3.0&from=en&to=af (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f83aa63fc18>, 'Connection to api-eur.cognitive.microsofttranslator.com timed out. (connect timeout=10)'))

I have configure a Private Endpoint to Cognitive Services, but that doesn't help. Any ideas?

It looks like you have a Synapse workspace that does not have any outbound connectivity (data exfiltration protection is turned on). We are still in the progress of enabling Cognitive services integration from these workspaces. Currently it works with private endpoints for Anomaly Detector and Text Analytics. We are looking into the root cause of this issue with Translator and will get back when we know more.

Thanks, Nellie

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM