Docker Community Forums

Share and learn in the Docker community.

Unable to make rest api call from django view


(Rajagola) #1

I have 2 containers. one with django app and other with flask app.
From django app view, I’m calling rest api [rest api inside flask app] in this way.

django view
def view(request)
r = requests.get(‘http://ip:5000’)

But I am getting error ’ (‘Connection aborted.’, error(113, ‘No route to host’))'
But if I call the same rest api from plain python file(external from docker). It runs fine. snip below

##snip
python testflask.py
Hello World! I have been seen 58 times.
##snip

import requests r= requests.get('http://ip:5000') print(r.text)

Please let me if know, If something is required.

Thanks
Raja


(Jeff Anderson) #2

What are the commands that you issue to start each container? The answer will depend largely on exactly what you are doing?

docker run ...
docker run ...

Regards


(Rajagola) #3

For django container, I have a Dockerfile and docker-compose.yml file [web + postgres]. I run this using the docker-compose up. I know basically docker-compose builds and runs the images.

For Flask, I also have a Dockerfile and docker-compose.yml file[flask+redis]. I run this using the docker-compose up command.

Inside the view of django app, I make a http request to this flask api.

Thanks