【问题标题】:"requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))"“requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))”
【发布时间】:2020-12-18 06:30:43
【问题描述】:

我正在尝试连接到 https://apis.digital.gob.cl/fl/feriados/2020,但在与其他 URL 完美配合的脚本上收到 requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)) 错误。

代码:

import requests

response = requests.get('https://apis.digital.gob.cl/fl/feriados/2020')
print(response.status_code)

【问题讨论】:

    标签: python python-3.x api python-requests response


    【解决方案1】:

    问题是网站过滤掉了没有正确User-Agent的请求,所以只使用来自MDN的随机请求:

    requests.get("https://apis.digital.gob.cl/fl/feriados/2020", headers={
    "User-Agent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      • 2023-01-10
      • 2020-12-04
      • 2022-12-04
      相关资源
      最近更新 更多