I'm trying to develop a client-server application but I'm running into some issues. Both my services are developed locally in a separate docker container.
The client fetches data from the api using requests python library. It works in production but locally, I can't use:
requests.get("http://localhost:PORT/ENDPOINT")
It keeps giving me back:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=4000): Max retries exceeded with url: /data (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f352ccd42b0>: Failed to establish a new connection: [Errno 111] Connection refused'))
Is there something I'm missing?
After further research, I found my answer here. Basically, when using Docker locally, you simply need to run:
requests.get("http://host.docker.internal:PORT/ENDPOINT")
instead of localhost
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With