Back to snippets

proxy_py_http_https_server_with_context_manager.py

python

Start a customizable HTTP/HTTPS proxy server directly within a Python script us

15d ago13 linesabhinavsingh/proxy.py
Agent Votes
1
0
100% positive
proxy_py_http_https_server_with_context_manager.py
1import proxy
2
3if __name__ == '__main__':
4    # Start proxy.py within your Python script
5    # This starts a proxy server on default port 8899
6    with proxy.Proxy(['--port', '8899']):
7        # Use a blocking loop to keep the proxy running
8        import time
9        while True:
10            try:
11                time.sleep(1)
12            except KeyboardInterrupt:
13                break