krose / entsoeapi

An R Wrapper for the Entso-E API.
Other
17 stars 4 forks source link

Missing or invalid security token #14

Closed rjnskl closed 4 months ago

rjnskl commented 2 years ago

Ran into this error after obtaining a new security token and saving it in the .Renviron file (and trying to add it directly to my R script as well). I get this after running the example code in the github readme.

Is there anything else I could try to make sure the token has been saved? thanks!

https://transparency.entsoe.eu/api?documentType=A65&processType=A16&outBiddingZone_Domain=10Y1001A1001A83F&periodStart=201912312300&periodEnd=202001012200&securityToken= ...
Error in api_req(url) : 
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Error</title>
</head>
<body>Unauthorized. Missing or invalid security token</body>
</html>
krose commented 2 years ago

Can you add the function you are trying to call in the example? Did you remember to restart R after you added the ENTSOE_PAT to the .Renviron file? Do you get a result if you run this snippet?: Sys.getenv("ENTSOE_PAT")

RudiHIbk01 commented 4 months ago

Hi @krose I do have the same problem when using the following code:

test_ger_da_mcp_april=en_transmission_day_ahead_prices (eic = ger_cty[,1], period_start = lubridate::ymd("2024-04-01", tz = "CET"), period_end = lubridate::ymd_hm("2024-04-07 23:00", tz = "CET"))`

ger_cty[,1] returns the AreaCode for Germany, fyi. But the error message following is exactly the same as @rjnskl.

https://web-api.tp.entsoe.eu/api?documentType=A44&in_Domain=10Y1001A1001A83F&out_Domain=10Y1001A1001A83F&periodStart=202403312200&periodEnd=202404072100&securityToken=<mySecToken>...
Fehler in api_req(url) : 
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Error</title>
</head>
<body>Unauthorized. Missing or invalid security token</body>
</html>

And Sys.getenv("ENTSOE_PAT") returns my correct security token in the way "<mySecToken>" (replaced the token values by text). Security token is for the RESTful API, and the wrapper does utilise that right? Can not wrap my head around where the problem is. I am using a Win10 machine and running R 4.3.3 and R-Studio 2023.12.1 Buidl 402 if this is of any concern. Thankful for any help. :)

sbudai commented 4 months ago

Hey @RudiHIbk01,

Yes, the security token is for the RESTful API.
According to the related guide, the web API can be accessed via web browser using Get method. Just simply put https://web-api.tp.entsoe.eu/api?documentType=A44&in_Domain=10Y1001A1001A83F&out_Domain=10Y1001A1001A83F&periodStart=202403312200&periodEnd=202404072100&securityToken=MYTOKEN into your web browser's address bar. (The MYTOKEN part should be replaced with your token without any quotes.)
If you do so and your token is valid, then you should get back this response:
image
If you get back the "Unauthorized. Missing or invalid security token" error message, then turn to ENTSO-E.

RudiHIbk01 commented 4 months ago

@sbudai thank you for the advice. Not understood what the wrapper was doing in the background initially. Took me a minute. XD But than I found the problem. I did store the security token in the .Renviron file as was described in the Readme "<MySecToken>". Though that <> was a required style for the reqest using the API, but this was the problem in the end. Getting rid of <> and only doing it in that way "MySecToken" solved the problem. As a reminder, restart the R-Studio session after changing the .Rviron file. Thank you for the advice once again and hope it'll help others who run in to the same problem.

Cheers :)

sbudai commented 4 months ago

Thanks for the feedback! I have re-edited the README accordingly.