Search code examples
pythonpython-3.xapipython-requestsresponse

"requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))"


I'm trying to connect to https://apis.digital.gob.cl/fl/feriados/2020, but I get an requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)) error on a script that works perfectly with other URLs.

The code:

import requests

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

Solution

  • The issue is that the website filters out requests without a proper User-Agent, so just use a random one from 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"
    })