【发布时间】:2017-12-08 00:42:39
【问题描述】:
我正在使用 python shell 与代理服务器一起测试请求。 在阅读文档 (http://docs.python-requests.org/en/master/user/advanced/) 和一些 stackoverflow 线程后,我正在执行以下操作:
import requests
s = requests.session()
proxies = {'http': 'http://90.178.216.202:3128'}
s.proxies.update(proxies)
req = s.get('http://jsonip.com')
在此之后,如果我打印 req.text,我会得到: u'{"ip":"我当前的IP(不是我之前插入的代理服务器IP)","about":"/about", ......}'
您能否解释一下为什么我得到的是我的计算机的 IP 地址而不是代理服务器的 IP 地址? 我是不是在某个地方出错了,还是我期望在这里发生错误的事情? 我是请求 + 代理服务器的新手,所以我想确保我理解这一点。
更新 我的代码中也有这个:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'}
s.headers.update(headers)
谢谢 维托里奥
【问题讨论】:
标签: python proxy python-requests ip-address