Create HTTP proxy environment using docker
Project description
This is a python module that starts a Squid proxy running in a docker container, and sets up an environment for using this proxy to handle HTTP(S) requests both from python code and external programs. The purpose is mainly for testing proxy support in code that needs to make HTTP(S) requests. The proxy supports both HTTP and HTTPS, and Basic proxy authorization.
Using an existing HTTP proxy
If a proxy is already set in the http_proxy environment variable, the newly created squid proxy will still work by using the existing proxy as “cache peer”. If you don’t want this, delete http_proxy from the environment before starting the temporary proxy.
Usage
from proxyenv.proxyenv import ProxyFactory proxyfact=ProxyFactory() # Example for using urllib from six.moves.urllib import request with proxyfact() as proxy: opener = request.build_opener(proxy.get_handler) opener.open(url) # Example for starting external program with proxy-related environment # variables from subprocess import check_output with proxyfact(user="johndoe:secret", port=3077) as proxy: check_output(["/usr/bin/wget", url])
Please use the main program in proxyenv/proxyenv.py as additional source of documentation.
The proxyenv script
The package also contains a console script proxyenv.
usage: proxyenv [-h] [-p PORT] [-u USER] [-i IMPL] [-s] [-w] [-v] [URL [URL ...]] positional arguments: URL an URL to retrieve optional arguments: -h, --help show this help message and exit -p PORT, --port PORT proxyport to use (default: 3128) -u USER, --user USER proxy user in user:password format -i IMPL, --impl IMPL set implementaton (cmdline or api, default: api) -s, --shell open a shell in new environment -w, --wait wait for input -v, --verbose verbose output
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file proxyenv-0.5.1.tar.gz
.
File metadata
- Download URL: proxyenv-0.5.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e73caf8b063b7fbfb93b67e725a71469768262a9dddb4d9dfb79bb1e84cab4b9 |
|
MD5 | 9a2f019e185aa3ade51a349d618c03c4 |
|
BLAKE2b-256 | 699846baccf9ce353828726e0d302dad201e634fe4b50f6f61891f0721f40789 |