【问题标题】:python requests fails when using proxy behind a router在路由器后面使用代理时python请求失败
【发布时间】:2016-01-26 03:53:20
【问题描述】:

我的代码是这样的:

import requests
proxies = {'http':'ip:port'}
r = requests.get('http://example.com', proxies = proxies)

当我在一台具有唯一 IP 地址的 PC 上运行此代码时,它运行良好, 但是,当我在 路由器后面 的 PC 中运行此代码时,它无法得到任何响应。 检查代理服务器后,发现连接不在代理服务器的日志中。

我不知道这个,请帮忙,非常感谢。

在@MilkeyMouse 的帮助下,我将代码更改为:

proxies = {'http':'http://ip:port'}

但还是不行。

【问题讨论】:

标签: python proxy python-requests router


【解决方案1】:

从 Requests 2.0.0 开始,您需要向代理添加一个方案。见the section in the Requests docs

import requests

proxies = {
  "http": "http://10.10.1.10:3128",
  "https": "http://10.10.1.10:1080",
}

requests.get("http://example.org", proxies=proxies)

注意代理 URL 前的 http://

【讨论】:

  • 感谢您的回答,我试过了,还是不行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-31
  • 2020-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-18
相关资源
最近更新 更多