supman
V2EX  ›  问与答

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

  •  
  •   supman · May 1, 2015 · 3089 views
    This topic created in 4055 days ago, the information mentioned may be changed or developed.
    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 replies    2015-05-02 10:43:00 +08:00
    binux
        1
    binux  
       May 1, 2015   ❤️ 1
    X-Forwarded-For
    supman
        2
    supman  
    OP
       May 1, 2015
    @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  
       May 2, 2015   ❤️ 1
    @supman 用http://ipecho.net/plain看看
    大多数代理会为你加上X-Forwarded-For,以方便上游服务统计,以及转移责任
    Septembers
        4
    Septembers  
       May 2, 2015 via Android
    @ryd994 高匿代理除外
    zeayes
        5
    zeayes  
       May 2, 2015
    服务端校验的是remote_addr吧,这个无法伪造。
    binux
        6
    binux  
       May 2, 2015
    @binux 不是让你加这个 header,而是你要阻止代理加这个 header
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   849 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 20:02 · PVG 04:02 · LAX 13:02 · JFK 16:02
    ♥ Do have faith in what you're doing.