bab689
bab689

Reputation: 239

Trouble connecting to AMLS web service on AKS using Python requests

I am having trouble contacting an AMLS web service hosted on AKS in a vnet. I am able to successfully provision AKS and deploy the models, but I am not able to access the web service using the Python requests module:

headers = {'Content-Type':'application/json',
           'Authorization': 'Bearer ' + <AKS_KEY>}
resp = requests.post(<AKS_URI>, json={"data":{"x": "1"}}, headers=headers)
print(resp.text)

I get the following error:

Error: HTTPConnectionPool(host='', port=80): Max retries exceeded with url: <AKS_URL> (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f33f6035a10>: Failed to establish a new connection: [Errno 110] Connection timed out'))

However, I am able to successfully connect to the web service using Postman:

curl --location --request POST <AKS_URI> \
--header 'Authorization: Bearer <AKS_KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{"data": {"x": "1"}}'

If I load the AKS service in my AMLS workspace aks_service.run() also gives me the same error message. I don't have these problems when I deploy without vnet integration.

What could be causing this?

Upvotes: 0

Views: 139

Answers (2)

bab689
bab689

Reputation: 239

I fixed this by adding an inbound security rule enabled for the scoring endpoint in the NSG group that controls the virtual network.

This should be done so that the scoring endpoint can be called from outside the virtual network (see documentation), but apparently Postman can figure out how to access the endpoint without this security rule!

Upvotes: 1

Anders Swanson
Anders Swanson

Reputation: 3961

I agree it is very weird. My initial reaction was that there's a tiny string formatting issue happening with b/w your requests request and your curl request. But I see that you're getting the same error with aks_service.run(). Perhaps reading more about how to secure the deployed service would help?

Upvotes: 0

Related Questions