Search…
⌃K

Python

Examples of python requests with our residential packages are shown using the popular Requests and urllib3 libraries.

Python Requests

In this example, we use the Residential proxy below:
residential.pingproxies.com:7777:customer-tt_pp_lz_5051-sessid-Z9tCGVYHu:23n22mk22
This proxy is split into four parts separated by colons. We first save the proxy as a string variable, then split it into four parts at each colon (:) and then add it, with authentication, to our proxy dictionary.
proxy_string= "residential.pingproxies.com:7777:customer-tt_pp_lz_5051-sessid-Z9tCGVYHu:23n22mk22"
proxy_parts = proxy_string.split(":")
ip_address = proxy_parts[0]
port = proxy_parts[1]
username = proxy_parts[2]
password = proxy_parts[3]
proxies = {
"http" :"http://{}:{}@{}:{}".format(username,password,ip_address,port),
"https":"http://{}:{}@{}:{}".format(username,password,ip_address,port),
}
# HTTP
r = requests.get("http://www.google.com/", proxies=proxies)
r.status_code # 200 OK

Python urllib3

In this example, we use the Residential proxy below:
residential.pingproxies.com:7777:customer-tt_pp_lz_5051-sessid-Z9tCGVYHu:23n22mk22
This proxy is split into four parts separated by colons. We first save the proxy as a string variable, then split it into four parts at each colon (:) and then using the ProxyManager function in urllib3 we add and authenticate the proxy.
from urllib3 import ProxyManager, make_headers
proxy_string= "residential.pingproxies.com:7777:customer-tt_pp_lz_5051-sessid-Z9tCGVYHu:23n22mk22"
proxy_parts = proxy_string.split(":")
ip_address = proxy_parts[0]
port = proxy_parts[1]
username = proxy_parts[2]
password = proxy_parts[3]
default_headers = make_headers(proxy_basic_auth='{}:{}'.format(username,password))
http = ProxyManager("http://{}:{}/".format(ip_address,port), proxy_headers=default_headers)
# Now you can use `http` as you would a normal PoolManager
r = http.request('GET', 'https://www.google.com/')
Last modified 2mo ago