-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a "check authentication" function #111
Comments
Thanks for your proposal. We are evaluating it. |
Is it already being evalutated? I now test this by requesting "dummy" dataset, and then catch the Exception for a nonexistent dataset, I get a HTTPError when the authentication fails. The exception used to be a RuntimeError, so from 0.7.0 to 0.7.2 my code broke. I would really just like to have a method in cdsapi that checks whether the authentication is valid and returns a boolean (or an error) |
@ALopAlos has this been evaluated already. My workaround now fails since |
@ALopAlos it turns out this feature is already present in cdsapi, so it does not have to be considered anymore. One could just do this: # check if the authentication is succesful, remove credentials if it fails
try:
c = cdsapi.Client()
c.client.check_authentication()
except HTTPError as e:
cds_remove_credentials_raise(reason=f'Authentication failed: {e}') |
Is your feature request related to a problem? Please describe.
When running
c = cdsapi.Client()
it checks whether there is a CDS apikey in theCDSAPI_KEY
environment variable or in the~/.cdsapirc
file. This is useful. However, it does not check whether this key works. When you want to check if a user is indeed authorized (the apikey is correct) and properly catch it if it is not the case (but pass if authentication succeeds), one would have to do something like this:Describe the solution you'd like
It would already be helpful if not all cdsapi errors would be
RuntimeError
s. A specific cdsapiAuthenticationFailedError
would be useful. What would be even better is if there would be a function available that checks the authentication. Something like this:This function then fails if the apikey is incorrect (or authentication fails for another reason). Could this be added?
Describe alternatives you've considered
The cumbersome workaround above.
Additional context
If there is no
~/.cdsapirc
file yet, we getException("Missing/incomplete configuration file")
. It would be convenient if this genericException
is replaced with a standardFileNotFoundError
so this specific error can be catched more easily.Organisation
Deltares
The text was updated successfully, but these errors were encountered: