I'm trying to get the response JSON from the following API endpoint https://datos.madrid.es/egob/catalogo/205026-0-cementerios.json. My code is:
import requests
url = 'https://datos.madrid.es/egob/catalogo/205026-0-cementerios.json'
r = requests.get(url)
r.json()
It fails with the error:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
If I get the encoding from the request, it's empty. So I've tried to force the encoding before accesing it, with no success:
import requests
url = 'https://datos.madrid.es/egob/catalogo/205026-0-cementerios.json'
r = requests.get(url)
r.encoding = 'utf-8'
r.json()
gives the same error.
r.text
returns something like:
'\x00\x00\x01\x00\x01\x00 \x00\x00\x01\x00\x18\x0 .......
so looks it's not decoding properly the response.
How can I get it successfully decoded?