如何使用Python3HTTP库创建HTTP代理处理程序
我正在尝试定义一个代理处理程序,以便在代理公司后面使用http.client。我知道如何使用或定义urllib的代理处理程序:如何使用Python3HTTP库创建HTTP代理处理程序,python,python-3.x,Python,Python 3.x,我正在尝试定义一个代理处理程序,以便在代理公司后面使用http.client。我知道如何使用或定义urllib的代理处理程序: http_proxy_full_auth_string = "http://"+"%s:%s@%s:%s" % (http_proxy_user, http_proxy_passwd, http_proxy_server, ht
http_proxy_full_auth_string = "http://"+"%s:%s@%s:%s" % (http_proxy_user,
http_proxy_passwd,
http_proxy_server,
http_proxy_port)
proxy_handler = urllib.request.ProxyHandler({"http": http_proxy_full_auth_string})
opener = urllib.request.build_opener(proxy_handler)
urllib.request.install_opener(opener)
resp = urllib.request.urlopen(uri).read()
使用http.client
附言:很抱歉英语水平很低…请参阅python 3文档
import http.client
conn = http.client.HTTPSConnection("proxy_domain", 8080)
conn.set_tunnel("www.python.org")
conn.request("HEAD","/index.html")
这可能是一条老线索,但人们可能会像我一样偶然发现它,不知道如何进行身份验证
import http.client
import base64
auth_hash = base64.b64encode(b"username:password").decode("utf-8")
conn = http.client.HTTPSConnection("proxy-ip or hostname", port="proxy-port")
conn.set_tunnel(
"example.com",
headers={"Proxy-Authorization": f"Basic {auth_hash}"})
conn.request("GET", "/")
这就是使用基本身份验证的方法。如何设置经过身份验证的代理?