ExtProxy
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. Don't need to worry about the patching, you can using everything like before, or you can unpatch it at any time.
Installation
pip install ExtProxy
Or download and Install from source code
python setup.py install
Compatibility
- Python >= 2.7
- Require PySocks to support SOCKS proxy type
Usage
# 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 = "http://127.0.0.1:8080"
# Use HTTPS proxy, use `set_https_proxy` to custom proxy's SSL verify mode
import ssl
proxy = "https://127.0.0.1:8443"
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://127.0.0.1:1080"
# Set proxy via system/python environment variables
import os
os.environ["HTTP_PROXY"] = proxy
os.environ["HTTPS_PROXY"] = proxy
print(urlopen("https://httpbin.org/ip").read().decode())
# Set proxy via ProxyHandler
opener = build_opener(ProxyHandler({
"http": proxy,
"https": proxy
}))
print(opener.open("https://httpbin.org/ip").read().decode())
# Restore monkey patch, then HTTPS, SOCKS proxy use can not continue working
extproxy.restore_items()
License
ExtProxy is released under the MIT License.
Metadata
Release files for ExtProxy 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ExtProxy-1.0.3.tar.gz | 9.8 kB | Without provenance | Details for ExtProxy-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ExtProxy-1.0.3-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for ExtProxy-1.0.3-py2.py3-none-any.whl |
Total release size: 21.8 kB
Release files / ExtProxy-1.0.3.tar.gz
| Download URL | ExtProxy-1.0.3.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4501949cb4885801bac5ae635231df0f67bfe17661a5202d6989bc25d2f124a0
|
|
BLAKE2b-256 checksum How to use checksums |
16ef3b89fd42631e55c7ff6c0c13f287164f8e603454ce9b77a12df42c7e79fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/60.5.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.9
|
Release files / ExtProxy-1.0.3-py2.py3-none-any.whl
| Download URL | ExtProxy-1.0.3-py2.py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
dbe32731cf03392dac1d911386b433c65e280b6bb6c3109d6ca696b1f3414fb7
|
|
BLAKE2b-256 checksum How to use checksums |
e253d00f81b697d1f496b83b5c801dee4673ba485c34dc894124380cfb43fbf3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/60.5.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.9
|
Security for ExtProxy 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.