Home > Blockchain >  Python Docker request sending [duplicate]
Python Docker request sending [duplicate]

Time:09-22

I'm trying to exchange data between a scrapping script and a REST API which is based on flask. The REST API is hosted localy on my machine (localhost) however the scrapping script is runned on a docker container. While sending the data I got the following issue after sending a post request from the docker container to the localhost (REST API).


def post_project(url, json):
    return requests.post(url=url, json=json)

requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /api/projects (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f02c65447c0>: Failed to establish a new connection: [Errno 111] Connection refused'))

I guess the problem is caused by the docker container since its looking for its localhost and not the localhost of the machine(REST API), are there any solutions to solve this problem ?

Kind regards.

CodePudding user response:

When you send request to 127.0.0.1:5000 inside docker container you send request to docker container.

See this post to learn how to send request to docker host

  • Related