Requests - Proxy



So far, we have seen clients directly connecting and talking to the server. Using proxy, the interaction happens as follows −

  • The client sends a request to the proxy.
  • The proxy sends the request to the server.
  • The server sends back the response to the proxy.
  • The proxy will send a response back to the client.

Using Http-proxy is additional security assigned to manage the data exchange between client and server. The requests libraries also have provision to handle proxy, by using the proxies param as shown below −

Example

import requests
proxies = {
'http': 'http://localhost:8080'
}
res = requests.get('http://httpbin.org/', proxies=proxies)
print(res.status_code) 

The request will route to http://localhost:8080 URL.

Output

200
Advertisements