如何使用代理PAC文件python urllib或请求?

Kay*_*rix 5 python proxy pac urllib python-requests

如何在HTTP库(如urllib或请求)中包含我的自动代理配置文件.

pacfile = 'http://myintranet.com/proxies/ourproxies.pac'
proxy = urllib3.ProxyManager(????????????????)
Run Code Online (Sandbox Code Playgroud)

小智 9

我已经创建了一个名为PyPAC的纯Python库,它应该可以满足您的需求.它提供了一个子类,requests.Session其中包括荣誉PAC,并包括PAC自动发现.


Luk*_*asa 7

目前,在urllib3或请求中不直接支持代理PAC文件.虽然原则上可以为代理PAC文件添加支持,但由于它们是需要解释的Javascript文件,因此提供基础广泛的支持可能非常困难.

原则上你可以使用requests/urllib3来请求代理PAC文件,然后将它传递给类似Node.JS的东西进行解释,然后用Python解析结果以传递给urllib3/requests,但是没有任何类似的东西是开箱即用的. .


Mar*_*des 5

使用 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'))
Run Code Online (Sandbox Code Playgroud)

你会得到 200