Reputation: 1989
Hi I'm trying to get REST request from a certain URL and if I input the url directly in the browser it works ok and output is as show in the image below
If I also try to query the url via native python on the same server where my django app is and it works fine too.
The problem is when i put the request in view.py in my django project I get a connection error as the the title of this question.
import requests
def my_method(request):
response = requests.get('http://10.150.20.103:8000/se/se-seid')
special_events_dashboard_events = response.json()
for event in special_events_dashboard_events['events']:
context['special_events'].append(event)
return render(request, 'updates/updates_network.html', context)
When I check the page in the browser, I get this error.
The REST API url is of different IP Address from my django application.
Is this a setting problem in my django application? How to work around this? I have been searching in the internet but I cant seem to find an answer to this.
Upvotes: 1
Views: 5569
Reputation: 1989
I found the answer to the problem here. It turns out its not django that is causing the problem rather its the Selinux settings of the server where my django project is deployed.
I found this similar permission error problem here, where the solutions states to enable httpd_can_network_connect context. After setting the context to ON, i can now connect to the api url.
Upvotes: 3