Village
Village

Reputation: 219

Using Python requests to GET not working - web client and browser works

I have my web app API running.

If I go to http://127.0.0.1:5000/ via any browser I get the right response.

If I use the Advanced REST Client Chrome app and send a GET request to my app at that address I get the right response.

However this gives me a 503:

import requests
response = requests.get('http://127.0.0.1:5000/') 

I read to try this for some reason:

s = requests.Session()
response = s.get('http://127.0.0.1:5000/')

But I still get a 503 response.

Other things I've tried: Not prefixing with http://, not using a port in the URL, running on a different port, trying a different API call like Post, etc.

Thanks.

Upvotes: 2

Views: 2119

Answers (2)

Village
Village

Reputation: 219

Just in case someone is struggling with this as well, what finally worked was running the application on my local network ip.

I.e., I just opened up the web app and changed the app.run(debug=True) line to app.run(host="my.ip.address", debug = True).

I'm guessing the requests library perhaps was trying to protect me from a localhost attack? Or our corporate proxy or firewall was preventing communication from unknown apps to the 127 address. I had set NO_PROXY to include the 127.0.0.1 address, so I don't think that was the problem. In the end I'm not really sure why it is working now, but I'm glad that it is.

Upvotes: 0

dphamcc
dphamcc

Reputation: 17

Is http://127.0.0.1:5000/ your localhost? If so, try 'http://localhost:5000' instead

Upvotes: 1

Related Questions