0

I have created and API using python+flask. When is try to hit the api using postman or chrome it works fine and I am able to get to the api.

On the other hand when I try to use python

import requests
requests.get("http://localhost:5050/")

I get 407. I guess that the proxy of the our environment is not allowing me to hit the localhost. But due to LAN settings in IE/Chrome the request went through.

I did try to set proxies , auth in request and now I start getting 502(bad gateway). If I see on the API side I can't see a request come through. What can I do to troubleshoot the same.

4
  • Try use 127.0.0.1:5050 instead http url. Commented Sep 5, 2017 at 10:55
  • I think you need to provide some header which are missing Commented Sep 5, 2017 at 11:02
  • Are you able to access it in your browser? Commented Sep 5, 2017 at 11:15
  • yes @DhKo i am able to access via browser Commented Sep 5, 2017 at 12:13

2 Answers 2

1

According to requests module documentation you can either provide proxy details through environment variable HTTP_PROXY (in case use Linux distribution):

$ export HTTP_PROXY="http://corporate-proxy:port"
$ python
>>> import requests
>>> requests.get('http://localhost:5050/')

Or provide proxies keyword argument to get method directly:

import requests

proxies = {
  'http': 'http://coporate-proxy:port',
}

requests.get('http://localhost:5050/', proxies=proxies)
Sign up to request clarification or add additional context in comments.

Comments

0

Try

import requests
from flask_cors import CORS, cross_origin

app = Flask(__name__)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
requests.get("http://localhost:5050/")

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.