Skip to main content

ExtProxy extend urllib2's ProxyHandler to support extra proxy types: HTTPS, SOCKS.

Project description


ExtProxy extend urllib2's ProxyHandler to support extra proxy types: HTTPS, SOCKS. It provides a consistent user experience like HTTP proxy for the users.

This script is using a non-side-effects monkey patch, it did not applied to build-in module socket, just inject some codes into Request, ProxyHandler, HTTPConnection, SSLContext method's processing. No need to worry about the patching, you can using everything like before, or you can unpatch it at any time.


Install from PyPI:

pip install ExtProxy

Or download and Install from source code:

python install


  • Python >= 2.7
  • Require PySocks to support SOCKS proxy type


# Target can be imported before monkey patching
from urllib.request import urlopen, build_opener, ProxyHandler

# Import extproxy, auto apply monkey patching by `extproxy.patch_items`
import extproxy

# Use origin HTTP proxy
proxy = ""

# Use HTTPS proxy, use `set_https_proxy` to custom proxy's SSL verify mode
import ssl
proxy = ""

cafile = "cafile path"
set_https_proxy(proxy, check_hostname=False, cafile=cafile)

context_settings = {
    "protocol": ssl.PROTOCOL_TLSv1_2,
    "cert_reqs": ssl.CERT_REQUIRED,  #
    "check_hostname": True,          #
    "cafile": "cafile path",         #
    "capath": "cafiles dir path",    #
    "cadata": b"ca data"             # Uesd to server auth
    "certfile": "certfile path",  #
    "keyfile": "keyfile path",    # Uesd to client auth
context = ssl._create_unverified_context(**context_settings)
 ...  # More custom settings
set_https_proxy(proxy, context=context)

# Use SOCKS proxy, `socks` can be: socks, socks4, socks4a, socks5, socks5h
# SOCKS4 does not support remote resolving, but SOCKS4a/5 supported
# 'socks' means SOCKS5, 'socks5h' means do not use remote resolving
proxy = "socks://"

# Set proxy via system/python environment variables
import os
os.environ["HTTP_PROXY"] = proxy
os.environ["HTTPS_PROXY"] = proxy

# Set proxy via ProxyHandler
opener = build_opener(ProxyHandler({
    "http": proxy,
    "https": proxy

# Restore monkey patch, then HTTPS, SOCKS proxy use can not continue working


ExtProxy is released under the MIT license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ExtProxy, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size ExtProxy-0.1.3-py2.py3-none-any.whl (11.6 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size ExtProxy-0.1.3.tar.gz (9.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page