Sometimes, we want to make requests via a proxy with Python.
In this article, we’ll look at how to make requests via a proxy with Python.
How to make requests via a proxy with Python?
To make requests via a proxy with Python, we can use the requests
module.
For instance, we write:
import requests
url = 'http://www.google.com'
proxy = '206.253.164.108'
r = requests.get(url, proxies={"http": proxy})
print(r)
We call requests.get
with the url
to make the request to and a dictionary with an entry with the 'http'
key set to a string with the proxy’s address.
Therefore, if the request is successful, we get something like:
<Response [200]>
returned.
Conclusion
To make requests via a proxy with Python, we can use the requests
module.