使用requests模块发送http请求时,报错:[WinError 10061] 由于目标计算机积极拒绝,无法连接

报错内容:

requests.exceptions.ProxyError: HTTPConnectionPool(host='127.0.0.1', port=80): Max retries exceeded with url: http://xxxxx.com/login (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000004CDB9E8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))

原因:

  requests请求前关了代理,而此时的requests请求默认使用本地代理

解决办法:

1、在请求前添加:

  os.environ['NO_PROXY'] = '423down.com'

2、在请求前添加:

  proxies = { "http": None, "https": None}
  requests.get(url, param, proxies=proxies)

3、在请求前添加:

  session = requests.Session()
  session.trust_env = False
  response = session.get(url, param)

posted @ 2019-07-18 10:56  天涯——咫尺  阅读(4105)  评论(0编辑  收藏