对urllib3设置全局代理

2024年3月11日17:50:32 发表评论 87 views
import asyncio
import urllib3
# 设置代理服务器的地址和端口
proxy_address = 'http://127.0.0.1:1081'

# 创建一个代理连接池
http = urllib3.ProxyManager(proxy_address)

# Monkey Patching:将urllib3的连接池替换为代理连接池
urllib3.PoolManager = lambda **kwargs: http

此方法可以对下载的东西全部代理

terminal的代理方法见之前的文章

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: