inyfee
V2EX  ›  问与答

python requests 报错: Cannot connect to proxy

  •  
  •   inyfee · Jun 16, 2015 · 9975 views
    This topic created in 4068 days ago, the information mentioned may be changed or developed.

    昨晚写一个的小程序,用到requests-future库。本来好好的,今天突然报这样的错误:

    `Traceback (most recent call last):
    File "/usr/lib/python3/dist-packages/requests/adapters.py", line 330, in send
    timeout=timeout
    File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 599, in urlopen
    'Socket error: %s.' % e)
    urllib3.exceptions.ProxyError: Cannot connect to proxy. Socket error: [Errno 111] Connection refused.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python3/dist-packages/requests/sessions.py", line 467, in get
    return self.request('GET', url, **kwargs)
    File "/usr/lib/python3/dist-packages/requests/sessions.py", line 455, in request
    resp = self.send(prep, **send_kwargs)
    File "/usr/lib/python3/dist-packages/requests/sessions.py", line 558, in send
    r = adapter.send(request, **kwargs)
    File "/usr/lib/python3/dist-packages/requests/adapters.py", line 381, in send
    raise ProxyError(e)
    requests.exceptions.ProxyError: Cannot connect to proxy. Socket error: [Errno 111] Connection refused.`

    代码则很简单:
    `

    from requests import Session
    s = Session()
    one = s.get('http://www.baidu.com/')
    `

    我不知道为什么突然会这样子报错,怀疑是不是我安装shadowsock后设置了全局代理,但我已经关闭了代理,也没有启动ss,在系统设置也设置了代理为无。

    目前使用的系统: elementary os

    5 replies    2015-06-17 05:58:44 +08:00
    Septembers
        1
    Septembers  
       Jun 16, 2015 via Android
    > printenv
    inyfee
        2
    inyfee  
    OP
       Jun 16, 2015
    @Septembers 谢谢。已使用 unset http_proxy 和 unset https_proxy 去除代理。但仍然报错。
    funagi
        3
    funagi  
       Jun 16, 2015
    根据这个: http://docs.python-requests.org/en/latest/user/advanced/#proxies

    检查环境变量HTTP_PROXY或HTTPS_PROXY是否被设置了
    inyfee
        4
    inyfee  
    OP
       Jun 16, 2015
    @funagi =。。=! 重启之后好了。
    Septembers
        5
    Septembers  
       Jun 17, 2015 via Android
    @yeelone 好像 Bash环境变量 区分大小写(写脚本的时候好像是这样的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1053 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:50 · PVG 06:50 · LAX 15:50 · JFK 18:50
    ♥ Do have faith in what you're doing.