Using Smart Proxy Manager with PythonΒΆ

Warning

zyte-smartproxy-ca.crt should be installed in your OS for the below code to work. You can follow these instructions in order to install it.

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,
    verify='/path/to/zyte-smartproxy-ca.crt'
)

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"
)

Smart Proxy Manager Certificate Authority can be downloaded here: zyte-smartproxy-ca.crt.