【问题标题】:Python3 Requests ConnectionError: ('Connection aborted.', OSError("(104, 'ECONNRESET')",)) with a specific URLPython3 请求 ConnectionError: ('Connection aborted.', OSError("(104, 'ECONNRESET')",)) 带有特定的 URL
【发布时间】:2017-04-02 06:36:28
【问题描述】:

这是我的代码。

import requests
r = requests.get('https://academic.oup.com/journals')

然后我得到了下面的错误;

ConnectionError: ('Connection aborted.', OSError("(104, 'ECONNRESET')",))

为什么我得到了错误? 我该怎么办? 该请求适用于其他 URL,例如 https://www.google.com

【问题讨论】:

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


    【解决方案1】:

    尝试在 HTTP 标头中指定用户代理:

    ❯❯❯ python3
    Python 3.5.2 (default, Sep 14 2016, 11:28:32) 
    [GCC 6.2.1 20160901 (Red Hat 6.2.1-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import requests
    >>> headers = requests.utils.default_headers()
    >>> headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
    >>> r = requests.get('https://academic.oup.com/journals', headers=headers)
    >>> r
    <Response [200]>
    

    另外,请确保您遵守website's robots.txt 中提到的规则

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      • 2017-05-13
      • 2019-02-02
      • 1970-01-01
      • 2020-11-04
      相关资源
      最近更新 更多