Here is a code snippet that illustrates how to use Zyte Smart Proxy Manager(formerly Crawlera) with Python Requests library:


import requests

url = "https://httpbin.org/ip"
proxy_host = "proxy.zyte.com"
proxy_port = "8011"
proxy_auth = "<Smart Proxy Manager API KEY>:" # Make sure to include ':' at the end
proxies = {
    "https": f"http://{proxy_auth}@{proxy_host}:{proxy_port}/",
    "http": f"http://{proxy_auth}@{proxy_host}:{proxy_port}/"
}

r = requests.get(url, proxies=proxies, verify='/path/to/zyte-proxy-ca.crt')

print(f"Requesting [{url}]\n"
    f"through proxy [{proxy_host}]\n\n"
    "Request Headers:"
    f"{r.request.headers}\n\n"
    f"Response Time: {r.elapsed.total_seconds()}\n"
    f"Response Code: {r.status_code}\n"
    f"Response Headers: {r.headers}\n\n"
    f"Response Cookies: {r.cookies.items()}\n\n"
    f"Response Body: {r.text}\n"
)


zyte-proxy-ca.crt file can be obtained from the Smart Proxy Manager account's setup page (SMART PROXY MANAGER CERTIFICATE section).



⚠️  Note: This code uses Requests version 2.18. Using previous versions can lead to authentication 407 errors, hence ensure Requests version is at least 2.18.