主要记录python代理需要账号密码才能登陆的用法.
urllib.request
from urllib.request import ProxyHandler, build_opener
import urllib
proxy = ‘username:password@url:port’
proxy_handler = ProxyHandler({
‘http’: ‘http://’ + proxy,
‘https’: ‘https://’ + proxy
})
opener = build_opener(proxy_handler)
urllib.request.install_opener(opener)
req = urllib.request.Request(url=url, headers=headers)
requests
import requests
proxies = {
“http”:“http://username:password@ip:port”
“https”: “https://username:password@ip:port”
}
requests.get(url, proxies=proxies)