Home > Mobile >  Max retries exceeded with url: Failed to establish a new connection: [Errno 111] Connection refused&
Max retries exceeded with url: Failed to establish a new connection: [Errno 111] Connection refused&

Time:01-28

I keep getting this error: HTTPConnectionPool(host='127.0.0.1', port=8001): Max retries exceeded with url: /api/v1/auth/sign_in (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f0f8cbdd430>: Failed to establish a new connection: [Errno 111] Connection refused'))

I searched through the stackoverflow and couldn't find the solution that would help me.

Here's my code example:

host = 'http://127.0.0.1:8001'

response = requests.request(method=request_data['method'],
                            url=f'{host}/{settings.ACCOUNTS_API_PREFIX}{request_data["url"]}',
                            json=json_data,
                            params=params,
                            headers=headers,
                            )

Basically I'm trying to send a POST request to authenticate myself on the service, however I keep getting the above error.

I have 2 containers - one is a web application (Django), another one is accounts that stores all details of the users to authenticate them.

Both containers are up and running, I can open the website, I can open the API swagger for accounts, however I can't send the POST request and get any response.

Containers settings as follows:

  container_1:
    build:
      context: ./container_1
      dockerfile: Dockerfile
    env_file:
      - '.env'
    stdin_open: true 
    tty: true        
    ports:
      - '8000:8000'
    expose:
      - 8000
    volumes:
      - ./data:/data
    working_dir: /data
    command: [ "./start.sh" ]
    networks:
      - web

  container_2:
        context: ./container_2
        dockerfile: Dockerfile
      env_file: 'accounts/settings/.env'
      stdin_open: true 
      tty: true        
      environment:
        - 'DJANGO_SETTINGS_MODULE=project.settings'
      expose:
        - 8000
      ports:
        - "8001:8000"
      volumes:
        - ./data:/app
      networks:
        - web

Can someone assist me to figure it out?

CodePudding user response:

Answer of @jordanm was right and it fixed my problem:

"Change host = 'http://127.0.0.1:8001' to host = 'http://container_2:8000'"

  • Related