【问题标题】:Why is Python requests.session() aborting connection?为什么 Python requests.session() 中止连接?
【发布时间】:2020-05-07 00:18:55
【问题描述】:

我在 python 项目中使用 requests 库从站点获取信息。

    @classmethod
def get_query(cls, url):
    """
    Getter method for retrieving information from exchange in the form of json
    :param url: specific path to follow base_rul for individualised requests
    :return: json object containing information sent by the API as per the request
    """
    base_url = 'https://api.hitbtc.com/api/2/'  # URL FOR THE EXCHANGE
    json = cls.session.get(base_url + url, timeout=5).json()  # fetches data from API
    return json

在收到此错误之前,我能够发出超过 500 个获取请求:

requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(10051, 'WSAENETUNREACH')"))

在文档中,他们提到了“保持活动”属性,但是他们没有在 requests.session() 中显示它的用法

【问题讨论】:

  • 你达到 api 速率限制了吗?
  • 我不是。限制高于 100 个请求/秒。我只做了 1。API 文档提到了“保持活动指令”,但没有显示它是如何实现的。Link to API Here
  • 如果您使用的是 Http 1.1,那么 keep alive 会由它自动处理。否则保持活动需要显式实现。你用的是哪个版本?
  • 我正在使用 Requests python 包并创建一个 Session 对象。文档提到“在会话中保持活动是 100% 自动的”。我认为该错误可能是由于网络中断或断电造成的。

标签: python python-requests


【解决方案1】:

我认为问题可能只是我的笔记本电脑要休眠了。

我可以将代码放在服务器或我的树莓派上来解决这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-02
    • 2010-12-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    相关资源
    最近更新 更多