Closed aazuspan closed 2 years ago
@aazuspan Thanks for the details and flagging the issue. Option 1 makes most sense, remove the file regardless of the returned authentication error.
Feel free to drop a PR and I'll gladly approve it. Glad you're finding this library useful :)
In case others run into this, a temporary workaround would be to remove the credential file manually.
rm ~/.usgs
Thanks for the quick response @kapadia! I'll open a PR with option 1 shortly.
If you run
api.logout
after your key has expired, it throws the following exception.This happens before it removes the old
TMPFILE
, so the expired key is kept and subsequent calls toapi.login
will also fail.I think this is a great tool and I'd be happy to contribute a PR if you're open to it, so I took a look at the source.
It seems like the underlying issues are: 1)
api.logout
fails on AUTH_EXPIRED errors, so you can't delete your old key. 2)api.login
callsapi._create_session
without a key which causesapi._get_api_key
to load the expired key, so you can't get a new key.I think those could be solved by: 1) Ignore AUTH_EXPIRED error codes for
api.logout
. The point of logging out is to deactivate and delete the key, so if it is already expired then the key just needs to be deleted. Maybe a warning could be raised, though? 2) Modifyapi._create_session
to skip theapi._get_api_key
call and just create a session without a key if none is provided. This would allowapi.login
to run and overwrite the expired key ifapi.logout
was never called. All other calls toapi._create_session
explicity pass a key, so they would be unaffected. At this point,api.logout
should be modified to accept an optionalapi_key
kwarg and explicitly pass a key (e.g. same pattern asapi.scene_metadata
).Let me know if you're open to PRs and if so, what you think of the plan.