Open-EO / openeo-r-client

R client package for working with openEO backends

Home Page:https://open-eo.github.io/openeo-r-client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTP 401 Unauthorize after successful login to https://openeo.dataspace.copernicus.eu

Rapsodia86 opened this issue · comments

Hello,
I do have a problem with logging into "https://openeo.dataspace.copernicus.eu".
The login process thru connection = login(connect(host = "https://openeo.dataspace.copernicus.eu")) goes fine:

Connected to service:  https://openeo.dataspace.copernicus.eu/openeo/1.2 
Please check the terms of service (terms_of_service()) and the privacy policy (privacy_policy()). By further usage of this service, you acknowledge and agree to those terms and policies.
→ Copy XXXX-XXXX and paste when requested by the browser
Press <enter> to proceed:
✔ Waiting for response from server [14.5s]
Login successful.

Btw. it ever asked me to paste that XXX-XXXX
but then after:

p = processes()
loadco1 = p$load_collection(id = "SENTINEL2_L2A", spatial_extent = list("west" = 21.963867, "east" = 23.241211, "south" = 43.539917, "north" = 45.192261), temporal_extent = list("2023-01-01", "2023-12-31"), bands = list("B8A", "B04", "SCL"))
savere1 = p$save_result(data = loadco1, format = "GTIFF")
result = compute_result(graph = savere1)

I get:

 HTTP 401 Unauthorized.
• SERVER-ERROR: Unauthorized.

create_job() gives the same 401 error

Thanks!

Btw. it ever asked me to paste that XXX-XXXX

That is fine. The message is created within the httr2 package that handles the login. It is just in case if the automatic transmission of the code fails.

HTTP 401 Unauthorized.
• SERVER-ERROR: Unauthorized.

That message hints that you are a registered user with the CDSE, but you currently have no rights to operate in the openEO environment. It either takes a while to activate your account or you have not enrolled to openEO yet. You can do the following:

  1. wait a day and check again
  2. try to use another openeo client like the openEO Webeditor, if you cannot use processing there, then we can rule out an issue with the openEO R-Client
  3. in that case I would advise to check your account settings in the CDSE and contact the CDSE Helpcenter

Hi,
Thanks for the quick answer!
I created the CDSE account a few months ago. Also, I can use the openEO Webeditor and run a process with no problems. I use the CDSE credentials to log into openRO Webeditor.
Is there any particular account setting I should check additionally?

OK, then it seems to be an issue with the openeo R client and because the login with the clients should work in both cases. I will try to figure out what the problem is.

To help me check for compatibility issues, can you state your R Version and the version of httr2 package?

Of course:

> sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] openeo_1.3.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11        pillar_1.9.0       compiler_4.2.2    
 [4] httr2_0.2.3        base64enc_0.1-3    class_7.3-22      
 [7] tools_4.2.2        digest_0.6.33      lubridate_1.9.2   
[10] jsonlite_1.8.7     lifecycle_1.0.4    tibble_3.2.1      
[13] timechange_0.2.0   pkgconfig_2.0.3    rlang_1.1.1       
[16] IRdisplay_1.1      DBI_1.2.0          cli_3.6.1         
[19] rstudioapi_0.15.0  fastmap_1.1.1      e1071_1.7-14      
[22] repr_1.1.6         httr_1.4.7         dplyr_1.1.2       
[25] generics_0.1.3     vctrs_0.6.5        rappdirs_0.3.3    
[28] tidyselect_1.2.0   classInt_0.4-10    grid_4.2.2        
[31] glue_1.6.2         sf_1.0-15          R6_2.5.1          
[34] fansi_1.0.6        magrittr_2.0.3     htmltools_0.5.5   
[37] units_0.8-5        utf8_1.2.4         KernSmooth_2.23-20
[40] proxy_0.4-27 

I might be on to something. Can you try the following configuration?

library(openeo)
con = connect(host = "https://openeo.dataspace.copernicus.eu")
login(config = list(client_id="cdse-default-openeo-oidc-client"))

No more 401!
However, now I am getting:

> loadco1 = p$load_collection(id = "SENTINEL2_L2A", spatial_extent = list("west" = 21.963867, "east" = 22.241211, "south" = 43.539917, "north" = 44.192261), temporal_extent = c("2023-01-01", "2023-01-15"), bands = "B08")
> savere1 = p$save_result(data = loadco1, format = "GTIFF")
> result = compute_result(graph = savere1,con = connection)
a character vector argument expected

The bands input must be a list, I think.

Could you try:
loadco1 = p$load_collection(id = "SENTINEL2_L2A", spatial_extent = list("west" = 21.963867, "east" = 22.241211, "south" = 43.539917, "north" = 44.192261), temporal_extent = c("2023-01-01", "2023-01-15"), bands = c("B08"))

@flahn That looks like an issue in CDSE's OIDC config, isn't it?
CDSE provides two client IDs and only the second option (client_id="cdse-default-openeo-oidc-client") works?

The bands input must be a list, I think.

Could you try: loadco1 = p$load_collection(id = "SENTINEL2_L2A", spatial_extent = list("west" = 21.963867, "east" = 22.241211, "south" = 43.539917, "north" = 44.192261), temporal_extent = c("2023-01-01", "2023-01-15"), bands = c("B08"))

Did not help, I tried:
bands = c("B08")
bands = list("B08")
bands = "B08"

No more 401! However, now I am getting:

> loadco1 = p$load_collection(id = "SENTINEL2_L2A", spatial_extent = list("west" = 21.963867, "east" = 22.241211, "south" = 43.539917, "north" = 44.192261), temporal_extent = c("2023-01-01", "2023-01-15"), bands = "B08")
> savere1 = p$save_result(data = loadco1, format = "GTIFF")
> result = compute_result(graph = savere1,con = connection)
a character vector argument expected

I noticed the the format identifier offered by CDSE is GTiff

f = list_file_formats()
f$output$GTiff

It might be that, or there is somehow a problem when the response data is stored to in the temp files on your local machine. You can check that, when you specify the parameter output_file in compute_result. Like output_file="c:/somewhere/on/disk.tif"

@flahn That looks like an issue in CDSE's OIDC config, isn't it? CDSE provides two client IDs and only the second option (client_id="cdse-default-openeo-oidc-client") works?

@m-mohr yep, I'm not sure if the openEO API allows multiple default clients or not. Internally, the first default client of the OIDC provider is picked that supports one of the implemented Authentication flows. Maybe I will add a little search that screens the client id for "openeo" as a substring.

No more 401! However, now I am getting:

> loadco1 = p$load_collection(id = "SENTINEL2_L2A", spatial_extent = list("west" = 21.963867, "east" = 22.241211, "south" = 43.539917, "north" = 44.192261), temporal_extent = c("2023-01-01", "2023-01-15"), bands = "B08")
> savere1 = p$save_result(data = loadco1, format = "GTIFF")
> result = compute_result(graph = savere1,con = connection)
a character vector argument expected

I noticed the the format identifier offered by CDSE is GTiff

f = list_file_formats()
f$output$GTiff

It might be that, or there is somehow a problem when the response data is stored to in the temp files on your local machine. You can check that, when you specify the parameter output_file in compute_result. Like output_file="c:/somewhere/on/disk.tif"

Hi,
Thanks for all the help!
Indeed, the lack of an output filename was resulting in the "a character vector argument expected" error. When I added a filename, the file got downloaded and saved.
No, here is an interesting part.
I have downloaded two files based on your comment about the format:
(1) p$save_result(data = loadco1, format = "GTIFF")
(2) formats = list_file_formats(); p$save_result(data = loadco1, format = formats$output$GTiff)

And those two images slightly differ in size. The file based on formats$output$GTiff is the smaller one. However, using describe() from R terra library I do not see any differences. Also, the same properties are shown for both in ArcGIS. And both are valid COGs.

@flahn The spec is relatively clear about it. If multiple default clients apply, the first one of them is chosen. So this looks like a backend issue.