请求。例外。连接错误:('连接已中止。',远程断开连接('远程端关闭的连接无响应',) [英] "requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))"

查看:30
本文介绍了请求。例外。连接错误:('连接已中止。',远程断开连接('远程端关闭的连接无响应',)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到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)

推荐答案

问题是网站没有正确的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"
})

这篇关于请求。例外。连接错误:('连接已中止。',远程断开连接('远程端关闭的连接无响应',)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆