Hi! I am a bioinformatics student interested in learning data analysis and drawing conclusions. Currently, I am working on a project where I will analyze the changes in the electricity price in Spain using Python.
To access the required data, I am using the ESIOS API and have obtained my TOKEN successfully. I can access the electricity price for today without any issues. However, I am facing difficulties accessing the price for previous days, such as yesterday or two days ago.
I wonder if anyone has encountered a similar issue or might have a solution for this problem. Could it be that I do not have sufficient permissions to access historical data? I have attached the relevant code below. Any assistance would be highly appreciated. Thank you!
import requests from datetime import datetime, timedelta def http_req(url_web, headers_pet, params_pet): return requests.get(url_web, headers=headers_pet, params=params_pet) def date_calc(days_before): return (datetime.now() – timedelta(days=days_before)).strftime(‘%Y-%m-%d’) TOKEN = “my_token” url = ‘https://api.esios.ree.es/indicators/1001’ headers = { ‘Accept’: ‘application/json; application/vnd.esios-api-v2+json’, ‘Content-Type’: ‘application/json’, ‘Host’: ‘api.esios.ree.es’, ‘Authorization’: f’Token token=”{TOKEN}”‘ } params = { ‘date’: date_calc(1) } response = http_req(url, headers, params) print(f’Fecha:{date_calc(1)}nRespuesta:{response.json()}’) —-Response—- Fecha:2023-07-18 Respuesta:{‘Status’: 403, ‘message’: ‘Forbidden’} Process finished with exit code 0
EDIT: I think it might be related to the way the URL is built. Perhaps I don’t need to use ‘params,’ but instead, edit the URL to insert the date there.
submitted by /u/MarioPnt
[link] [comments]