{"id":21075,"date":"2023-07-19T14:28:49","date_gmt":"2023-07-19T12:28:49","guid":{"rendered":"https:\/\/www.graviton.at\/letterswaplibrary\/issue-while-using-esios-api-spain-to-request-past-data\/"},"modified":"2023-07-19T14:28:49","modified_gmt":"2023-07-19T12:28:49","slug":"issue-while-using-esios-api-spain-to-request-past-data","status":"publish","type":"post","link":"https:\/\/www.graviton.at\/letterswaplibrary\/issue-while-using-esios-api-spain-to-request-past-data\/","title":{"rendered":"Issue While Using ESIOS API (Spain) To Request Past Data"},"content":{"rendered":"<p><!-- SC_OFF --><\/p>\n<div class=\"md\">\n<p>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.<\/p>\n<p>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.<\/p>\n<p>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!<\/p>\n<p><a href=\"https:\/\/api.esios.ree.es\/\">ESIOS API<\/a><\/p>\n<p> 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() &#8211; timedelta(days=days_before)).strftime(&#8216;%Y-%m-%d&#8217;) TOKEN = &#8220;my_token&#8221; url = &#8216;https:\/\/api.esios.ree.es\/indicators\/1001&#8217; headers = { &#8216;Accept&#8217;: &#8216;application\/json; application\/vnd.esios-api-v2+json&#8217;, &#8216;Content-Type&#8217;: &#8216;application\/json&#8217;, &#8216;Host&#8217;: &#8216;api.esios.ree.es&#8217;, &#8216;Authorization&#8217;: f&#8217;Token token=&#8221;{TOKEN}&#8221;&#8216; } params = { &#8216;date&#8217;: date_calc(1) } response = http_req(url, headers, params) print(f&#8217;Fecha:{date_calc(1)}nRespuesta:{response.json()}&#8217;) &#8212;-Response&#8212;- Fecha:2023-07-18 Respuesta:{&#8216;Status&#8217;: 403, &#8216;message&#8217;: &#8216;Forbidden&#8217;} Process finished with exit code 0  <\/p>\n<p>EDIT: I think it might be related to the way the URL is built. Perhaps I don&#8217;t need to use &#8216;params,&#8217; but instead, edit the URL to insert the date there.<\/p>\n<\/div>\n<p><!-- SC_ON -->   submitted by   <a href=\"https:\/\/www.reddit.com\/user\/MarioPnt\"> \/u\/MarioPnt <\/a> <br \/> <span><a href=\"https:\/\/www.reddit.com\/r\/datasets\/comments\/153t65o\/issue_while_using_esios_api_spain_to_request_past\/\">[link]<\/a><\/span>   <span><a href=\"https:\/\/www.reddit.com\/r\/datasets\/comments\/153t65o\/issue_while_using_esios_api_spain_to_request_past\/\">[comments]<\/a><\/span><\/p><div class='watch-action'><div class='watch-position align-right'><div class='action-like'><a class='lbg-style1 like-21075 jlk' href='javascript:void(0)' data-task='like' data-post_id='21075' data-nonce='65e0e39b87' rel='nofollow'><img class='wti-pixel' src='https:\/\/www.graviton.at\/letterswaplibrary\/wp-content\/plugins\/wti-like-post\/images\/pixel.gif' title='Like' \/><span class='lc-21075 lc'>0<\/span><\/a><\/div><\/div> <div class='status-21075 status align-right'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Hi! I am a bioinformatics student interested in learning data analysis and drawing conclusions. Currently, I am&#8230;<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[],"class_list":["post-21075","post","type-post","status-publish","format-standard","hentry","category-datatards","wpcat-85-id"],"_links":{"self":[{"href":"https:\/\/www.graviton.at\/letterswaplibrary\/wp-json\/wp\/v2\/posts\/21075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.graviton.at\/letterswaplibrary\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.graviton.at\/letterswaplibrary\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.graviton.at\/letterswaplibrary\/wp-json\/wp\/v2\/comments?post=21075"}],"version-history":[{"count":0,"href":"https:\/\/www.graviton.at\/letterswaplibrary\/wp-json\/wp\/v2\/posts\/21075\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.graviton.at\/letterswaplibrary\/wp-json\/wp\/v2\/media?parent=21075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.graviton.at\/letterswaplibrary\/wp-json\/wp\/v2\/categories?post=21075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.graviton.at\/letterswaplibrary\/wp-json\/wp\/v2\/tags?post=21075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}