【问题标题】:Python Error 104, connection reset by peerPython 错误 104,对等方重置连接
【发布时间】:2017-06-09 12:38:02
【问题描述】:

我在尝试向各种主机发出 Web 请求时遇到此错误。经过一番调试,我发现解决方案是通过 pip 更新 requests[security]。

【问题讨论】:

    标签: python python-3.x pip python-requests


    【解决方案1】:

    我在 Python2.7 请求中也遇到了这个问题。安装 "requests[security]" 与 pip 为我带来了明显的改进,但在快速连续的 1000 个请求中,我仍然会收到此错误 2 或 3 次。

    已解决实施重试,因为这似乎是一个非常临时的问题。现在就像一个魅力。

    import time
    import requests
    from requests.exceptions import ConnectionError
    
    # ...
    
    nb_tries = 10
    while True:
        nb_tries -= 1
        try:
            # Request url
            result = session.get("my_url")
            break
        except ConnectionError as err:
            if nb_tries == 0:
                raise err
            else:
                time.sleep(1)
    
    # ...
    

    【讨论】:

      【解决方案2】:

      运行

      sudo python3 -m pip install "requests[security]"

      sudo python -m pip install "requests[security]"

      解决这个问题。

      【讨论】:

      • 你真的不应该提倡使用 pip 作为 root,虽然
      猜你喜欢
      • 2016-03-03
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 2014-01-01
      • 1970-01-01
      • 2016-10-10
      • 2018-05-22
      相关资源
      最近更新 更多