“requests.exceptions.ConnectionError:('连接中止。',RemoteDisconnected('远程结束关闭连接而无响应',))”

Mar*_* M. 14 python api response python-3.x python-requests

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

代码:

import requests

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

Sup*_*mer 19

问题是该网站会过滤掉没有正确的请求,因此只需使用来自MDNUser-Agent的随机请求:

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"
})
Run Code Online (Sandbox Code Playgroud)