Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么代理服务器使用我的私有IP?_Python_Web Scraping_Http Proxy - Fatal编程技术网

Python 为什么代理服务器使用我的私有IP?

Python 为什么代理服务器使用我的私有IP?,python,web-scraping,http-proxy,Python,Web Scraping,Http Proxy,我正在尝试使用代理刮(这个代理服务器是一个免费的从互联网);特别是我想使用他们的IP,而不是我的私人IP。要测试我的脚本,我正在尝试访问“http://whatismyipaddress.com/“查看此站点看到的IP。事实证明,它将看到我的私有IP。谁能告诉我这里怎么了 import requests from fake_useragent import UserAgent def getMyIP(proxyServer,myPrivateIP): scrape_website =

我正在尝试使用代理刮(这个代理服务器是一个免费的从互联网);特别是我想使用他们的IP,而不是我的私人IP。要测试我的脚本,我正在尝试访问“http://whatismyipaddress.com/“查看此站点看到的IP。事实证明,它将看到我的私有IP。谁能告诉我这里怎么了

import requests
from fake_useragent import UserAgent

def getMyIP(proxyServer,myPrivateIP):

    scrape_website = "http://whatismyipaddress.com/"

    ua = UserAgent()
    headers = {'User-Agent': ua.random}
    
    try:
        response = requests.get(scrape_website,headers=headers,proxies={"https":proxyServer})
    except:
        faultString = proxyServer + " did not work; " + "\n" 
        print(faultString)
        return
    
    if myPrivateIP in str(response.content):
        print("They found my private IP.")

proxyServer = "http://103.250.158.23:61219"
myPrivateIP = "xxx.xxx.xxx.xxx"
getMyIP(proxyServer,myPrivateIP)
两件事:

  • 您设置了一个
    {'https':…}
    代理配置。这意味着对于任何HTTPS请求,它都将使用该代理。但是,您正在请求一个HTTP URL,因此无法使用该代理。改为或另外配置一个
    'http'
    代理
  • 如果代理在HTTP报头中转发您的IP,而目标服务器注意到了该报头,那么这将是一件非常倒霉的事情,除了使用不转发您的IP的不同代理之外,您什么也做不了。不过,我认为第1点更有可能是问题所在
  • 两件事:

  • 您设置了一个
    {'https':…}
    代理配置。这意味着对于任何HTTPS请求,它都将使用该代理。但是,您正在请求一个HTTP URL,因此无法使用该代理。改为或另外配置一个
    'http'
    代理
  • 如果代理在HTTP报头中转发您的IP,而目标服务器注意到了该报头,那么这将是一件非常倒霉的事情,除了使用不转发您的IP的不同代理之外,您什么也做不了。不过,我认为第1点更有可能是问题所在

  • 您只指定一个
    https
    代理,但发出
    http
    请求…代理服务器正在推进您的IP。除了使用不同的代理之外,您什么也做不了。虽然可能很难找到这样的代理。您只指定
    https
    代理,但发出
    http
    请求…代理服务器正在推进您的IP。除了使用不同的代理之外,您什么也做不了。虽然可能很难找到这样的代理。