问题描述
我正在尝试连接到'https://apis.digital.gob.cl/fl/feriados/2020',但我收到了“ requests.exceptions.ConnectionError:('Connection aborted。',Remotedisconnected('完美运行的脚本上python3中的远端关闭连接而没有响应',))“错误 与其他网址。
代码:
import requests
response = requests.get('https://apis.digital.gob.cl/fl/feriados/2020')
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"
})