无法使用请求连接到代理 Python

Can`t connect to a proxy using requests Python

我正在尝试使用 python 连接到 http 服务器,但在我向 https://httpbin.org/ip

发送获取请求后

我得到了正常的 ip public 就像我没有使用代理一样。

我们假设我的 public 不使用代理的 ip 是:10.10.10.10 这是我的代码:

proxies ={
        
    "http":"http://103.103.175.253:3128"
}
get = requests.get("https://httpbin.org/ip", proxies = proxies)
soup = bs(get.text,'html.parser')
print(soup.prettify())
print(get.status_code, get.reason)

我得到:

{
  "origin": "10.10.10.10"
}

200 OK

我应该收到“来源”:“103.103.175.253”

有人可以帮助我吗????

您正在连接到 https:// 站点,但您只指定了 http 代理。

您可以使用 http:// 协议,或指定另一个 https 代理。例如:

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

get = requests.get("http://httpbin.org/ip", proxies=proxies)  # <-- connect to http://
soup = BeautifulSoup(get.text, "html.parser")
print(soup.prettify())
print(get.status_code, get.reason)

打印:

{
  "origin": "103.103.175.253"
}

200 OK