Python
Capture HTTP/HTTPS traffic from Python with Proxyman
1. New Automatic Solution (v4.7.0 or later) ✅
Proxyman v4.7.0 or later can capture HTTP/HTTPS traffic from Python with 1-click.
1-click solution: No need to manually set HTTP Proxy config or trust the self-signed certificate.
Support many Python libraries: request, http.client, urllib3, httpx and aiohttp
How to use:
Open Proxyman -> Setup Menu -> Automatic Setup
Click on "Open New Terminal"
Accept the Apple Script permission prompt if needed
The New Terminal app is launched -> You can start your Python Backend Server, or Run scripts => Proxyman automatically captures all traffic.
Done ✅
Please check out the Automatic Setup page:
Automatic Setup2. Old Solution (Not recommended) ❌
1. Script Approach
Use the following script to automatically install/remove the certificate to Python.
Save the script to ~/desktop file with the name is
script.py
Add Certificate:
Remove Certificate
For macOS 12.2 or later, make sure you use python3
Credit to @novitae
2. Manual Approach
- Install Proxyman on the Python environment
By default, Python on macOS doesn't trust Proxyman self-signed certificates. As a result, you might encounter SSL Error if you try to intercept HTTPS traffic.
If you would like to intercept HTTPS Traffic from your Python script, you have to explicitly tell Python to use the Proxyman Root Certificate at ~/.proxyman/proxyman-ca.pem
Please follow the guideline:
Install Proxyman Certificate on Mac (If you've done it, please skip it. If not, please check out MacOS Guideline).
Run the following CLI on your Terminal app
3. Done.
- Revert the change
If you don't use Proxyman, please revert the change by commenting out:
in ~/.bash_profile
3. Troubleshooting
3.1 Proxyman could not capture HTTP traffic from my Python code.
Solution: Please use the Automatic Setup.
Reference
Last updated