Search code examples
python-3.xrestpython-requestsurllib

When accessing a Rest API via requests.get it times out. Same URL gets the response in browser


I am trying to access a Rest API that supports GET, POST, PUT, MOVE functions. When I try the URL using the browser to get list of files I get a response from the REST API. However, when I try to call the same URL via requests.get(url) I get:

(Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x000002D8CCFBC6A0>, 'Connection to timed out. (connect timeout=None)'))

What am I missing? Does it make any difference if I pass a JWT token within the URL?

URL in the browser returns a list in JSON.

import requests
url = "https://www.restapi.com/content?JWT-token"
x = requests.get(url)
print(x.status_code)

Solution

  • When you run the url within the browser it automatically finds the corresponding proxy for the url. I had to download the proxy file from browser's setting find the proxy mapping for that URL and add proxy parameters within the requests