Max retries exceeded with (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object [Errno -5] No address associated with hostname',))

Rohan shah picture Rohan shah · Apr 6, 2020 · Viewed 7.5k times · Source

I have build a flask application. This application makes an API call to a graphql server which has a url like "http://xyz:8080/graphql".

The application is containerized in docker container and runs on docker compose.

This exterenal graphql server is accessible from the chrome browser and api tools . but when the container calls the server url it gives an error like this.

**HTTPConnectionPool(host='xyz', port=8080): Max retries exceeded with url: /graphql (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f21777
f0c18>: Failed to establish a new connection: [Errno -5] No address associated with hostname',))**

the url is binded with a DNS and IP address is there as well. I dont have an IP address of the server and just the DNS i.e "xyz" any one faced this kind of issue? below is the class written to connect to graphql in application.

  import requests

class GraphQL:
  def graphql(self, query, variables = {}, headers = None):
    url = 'http://xyz:8080/graphql'
    response = requests.post(
        url = url,
        json = {'query': query, 'variables': variables},
        headers = headers
    )
    return response

Answer