问题
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(????????????????)
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/31528812/how-to-use-proxy-pac-file-for-python-urllib-or-request