How do I include my automatic proxy config file in HTTP libraries like urllib or requests.
pacfile = 'http://myintranet.com/proxies/ourproxies.pac'
proxy = urllib3.ProxyManager(????????????????)
I've created a pure-Python library called PyPAC which should do what you're looking for. It provides a subclass of requests.Session
that includes honours PACs and includes PAC auto-discovery.
Current there is no support for a proxy PAC file directly in urllib3 or requests. While support could in principle be added for proxy PAC files, because they are Javascript files that require interpretation it is likely to be extremely difficult to provide broad-based support.
In principle you could use requests/urllib3 to request the Proxy PAC file, then pass it to something like Node.JS for interpreting, then parse the results back in Python to pass to urllib3/requests, but nothing like that exists out of the box.
Use PYPAC.
from pypac import PACSession, get_pac
pac = get_pac(url='http://your/pac/url/file.pac')
session = PACSession(pac, proxy_auth=HTTPProxyAuth('your_user', 'password'))
print(session.get('http://www.google.com'))
you will get a 200
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With