python http代理_python中http.client使用代理

如果是http代理,可以直接搜索set_tunnel关键字找到想要的内容。

如果是socks代理,就比较麻烦了。下面贴代码:

import socks

def httpGet(url, resource, params=''):

conn = http.client.HTTPSConnection("127.0.0.1", 1080)

conn.set_tunnel(url)

conn.sock = socks.socksocket()

conn.sock.set_proxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 1080)

conn.sock.connect((url,80))###http:80 ,https:443

conn.request("GET", resource + '/' + params)

response = conn.getresponse()

data = response.read().decode('utf-8')

return json.loads(data)

post请求也一样

你可能感兴趣的:(python,http代理)