cdsapi fails to use CDSAPI_KEY environment variable
veenstrajelmer opened this issue · comments
What happened?
when not defining the ~/.cdsapirc
file but using environment variables only, the authentication fails when not explicitly passing the url/key variables to cdsapi.Client()
. This is odd since these environment variables are the default arguments in the __init__()
function:
Lines 248 to 255 in 0ad7f77
What are the steps to reproduce the bug?
minimal reproducible example:
import os
import cdsapi
os.environ["CDSAPI_URL"] = "https://cds.climate.copernicus.eu/api/v2"
os.environ["CDSAPI_KEY"] = "uid:apikey"
name = "reanalysis-era5-single-levels"
name = "dummy"
# # IT WORKS WHEN PROVIDING url and key manually
# c = cdsapi.Client(url=os.environ.get("CDSAPI_URL"),
# key=os.environ.get("CDSAPI_KEY"))
# # checks whether credentials (uid and apikey) are correct
# c.retrieve(name=name, request={})
# raises (expected) Exception: Resource dummy not found
# IT FAILS WHEN NOT DOING THIS, even though the Client class has these exact same arguments in its __init__() function
c = cdsapi.Client()
# checks whether credentials (uid and apikey) are correct
c.retrieve(name=name, request={})
# raises Exception: Missing/incomplete configuration file: C:\Users\veenstra/.cdsapirc
Version
0.6.1 (latest)
Platform (OS and architecture)
Windows 10 64 bit
Relevant log output
Exception: Missing/incomplete configuration file: C:\Users\veenstra/.cdsapirc
Accompanying data
No response
Organisation
Deltares
I just noticed the exact same thing. #92 should fix this.
(I noticed that there's a CDSAPI token in your snippet. You might want to remove it or replace it with a fake one in case you didn't do it already)
@malmans2 Woops, that was indeed meant to be replaced, thanks for this notification and the fix.