Warning

Zyte API is replacing Smart Proxy Manager. See Migrating from Smart Proxy Manager to Zyte API.

Using Smart Proxy Manager with Python#

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.

Here is a code example that illustrates how to use Smart Proxy Manager with Python Requests library:

import requests

url = "http://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": "http://{}@{}:{}/".format(proxy_auth, proxy_host, proxy_port),
      "http": "http://{}@{}:{}/".format(proxy_auth, proxy_host, proxy_port)}

r = requests.get(
    url,
    proxies=proxies,
)

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

To run the example first install and configure the Zyte CA certificate for the requests library.