2

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.

5
  • Have you tried setting the User-Agent? Commented Dec 3, 2015 at 21:06
  • Like this? requests.get('127.0.0.1:5000, headers = { 'User-Agent' : 'something' }) What would I set it to? Commented Dec 3, 2015 at 21:16
  • Hard to know for sure, but everyone likes to pretend to be Mozilla: headers = {'User-Agent': 'Mozilla/5.0'} Commented Dec 3, 2015 at 21:27
  • I tried this but no dice :/ Commented Dec 3, 2015 at 21:29
  • Try the Sesame Street school of debugging - one of these things is not like the other. There appears to be some difference between the working request and the non-working one, have to find it. 2 possible approaches come to mind: look at the server side (maybe logs?) and see what was received by the server or look at the client side (maybe Chrome developer tools) and see what was sent. Commented Dec 3, 2015 at 21:47

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

9 Comments

It is my localhost. I tried what you said and I'm getting a 404 now.
Yes. It returns 200 (ok/success)
Ok, what does your response say about the 503 error if you get the text? print(str(response.text))
Pretty generic 503 error, I can't post pictures yet but here is the wall of text:
A communication error occurred: "Connection refused" The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time. For assistance, contact your network support team.
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.