September 2018
Intermediate to advanced
426 pages
10h 46m
English
An interesting feature offered by the requests module is the possibility to make requests through a proxy or intermediate machine between our internal network and the external network.
A proxy is defined in the following way:
>>> proxy = {"protocol":"ip:port", ...}
To make a request through a proxy, the proxies attribute of the get method is used:
>>> response = requests.get(url,headers=headers,proxies=proxy)
The proxy parameter must be passed in the form of a dictionary, that is, you have to create a dictionary type where we specify the protocol with the IP address and the port where the proxy is listening:
import requestshttp_proxy = "http://<ip_address>:<port>"proxy_dictionary = { "http" : http_proxy}requests.get("http://example.org", ...