0

I have created a function with http trigger. Inside function, i have written python code which hits rest api and return json data as response.

request_headers = {"Authorization":"Api-Token {}".format(api_token)}

url = "https://<<host>>/e/54d139b9-23ee-466d-ad7a-f98e0bd8bdf4/{}?includeData=true&aggregationType=COUNT&relativeTime={}&entity={}".format(api_endpoint,relativeTime,entity)

response = requests.get(url, headers = request_headers)
return func.HttpResponse(json.dumps(response.json()))

It is running successfully in local.However the same code from function app giving below error

HTTPSConnectionPool(host='<<host>>', port=443): Max retries exceeded with url: /e/54d139b9-23ee-466d-ad7a-f98e0bd8bdf4/<<api_endpoint>>?includeData=true&aggregationType=COUNT&relativeTime=6hours&entity=<<entity>> (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fbe44681ac0>: Failed to establish a new connection: [Errno -5] No address associated with hostname'))

Can anyone help with this error?

Kashyap
  • 15,354
  • 13
  • 64
  • 103
Mahi
  • 77
  • 1
  • 2
  • 10
  • Sounds like a simple name resolution error. Try to add some logs to print output of name resolution, run it locally and then in cloud and update the question with output. See https://stackoverflow.com/a/11618198/496289 – Kashyap Feb 10 '21 at 21:59
  • But the same code is working fine in local. What happens when i deployed the code to function app? – Mahi Feb 11 '21 at 03:32
  • Great. If it works in local then use it in local! If everything worked everywhere we'll all be out of jobs. – Kashyap Feb 11 '21 at 16:12

1 Answers1

0

Agree with what Kashyap mentioned in comment, it seems there is something wrong with the host name in your url. I test with incorrect host in my code and reproduce the same error message with yours.

So please check if the <<host>> is correct if you just hard code it in url. And if it is not hardcode, it comes from some variables (for example if it comes from application settings of your function app), please make sure if you have added the variable to application settings in your function app. Because when we deploy the function app from local to azure, the variables in "local.settings.json" will not also be deployed to function app automatically, we need to add the variable to application settings manually after deployment.

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • I am not using any settings here, hostname is hardcoded and api_endpoint is passed as a parameter. – Mahi Feb 11 '21 at 03:33
  • @Mahi May I know how long does the request take ? And how did you deploy the function from local to azure ? – Hury Shen Feb 12 '21 at 03:40