Uncel_Liang 发表于 2020-3-26 10:20:23

无法使用代理

import urllib.request
import random
import json

url = 'https://ip.cn/'

req = urllib.request.Request(url)
#req.add_header('User-Agent','Test_Proxy_Python3.5_maminyao')
proxies = ['117.94.213.165:8118','119.179.136.97:8060','114.228.73.217:6666']
proxy = random.choice(proxies)
proxy_support = urllib.request.ProxyHandler({'http':proxy})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
opener.addheaders = [('User-Agent','Test_Proxy_Python3.5_maminyao')]

response = urllib.request.urlopen(url)
html = response.read().decode('utf-8')
print (json.loads(html)['ip'],json.loads(html)['country'],json.loads(html)['city'],)

#无论怎么改都是本机外网ip

zltzlt 发表于 2020-3-26 13:05:44

因为你的 IP 是 http,而网址协议是 https
页: [1]
查看完整版本: 无法使用代理