V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
supman
V2EX  ›  问与答

python 中 使用了代理, 但是 ip 还不改变是什么情况呢?

  •  
  •   supman · 2015-05-01 23:21:24 +08:00 · 2635 次点击
    这是一个创建于 3319 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import requests

    proxies = {
    "http": "http://115.28.11.130:3128",
    }

    url='http://www.ip138.com'
    response = requests.get(url=url,proxies=proxies)


    代理应该是连上了, 因为试了几个代理, 连接不上的会直接提示错误。 但是呢, 从返回的结果来看, ip根本就没有变化, 还是本机的ip。 请问 问题出在哪里了呢?
    6 条回复    2015-05-02 10:43:00 +08:00
    binux
        1
    binux  
       2015-05-01 23:30:12 +08:00   ❤️ 1
    X-Forwarded-For
    supman
        2
    supman  
    OP
       2015-05-01 23:47:18 +08:00
    @binux 求指教, 已经在headers 添加了代理的ip 以及端口, 但是结果还是不对。
    proxies = {
    "http": "http://115.28.11.130:3128",
    }
    headers = {
    "X-Forwarded-Port": "3128",
    "X-Forwarded-For": "115.28.11.130",
    }
    url='http://www.ip138.com'
    response = requests.get(url=url,proxies=proxies,headers=headers)
    ryd994
        3
    ryd994  
       2015-05-02 00:31:06 +08:00   ❤️ 1
    @supman 用http://ipecho.net/plain看看
    大多数代理会为你加上X-Forwarded-For,以方便上游服务统计,以及转移责任
    Septembers
        4
    Septembers  
       2015-05-02 01:24:37 +08:00 via Android
    @ryd994 高匿代理除外
    zeayes
        5
    zeayes  
       2015-05-02 07:55:51 +08:00
    服务端校验的是remote_addr吧,这个无法伪造。
    binux
        6
    binux  
       2015-05-02 10:43:00 +08:00
    @binux 不是让你加这个 header,而是你要阻止代理加这个 header
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   949 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 20:19 · PVG 04:19 · LAX 13:19 · JFK 16:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.