Skip to content
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

Setting API key from code still uses the API key in config.ini #231

Closed
raffaem opened this issue Dec 21, 2021 · 6 comments
Closed

Setting API key from code still uses the API key in config.ini #231

raffaem opened this issue Dec 21, 2021 · 6 comments

Comments

@raffaem
Copy link
Contributor

raffaem commented Dec 21, 2021

I'm setting my API key from code, by writing

from pybliometrics.scopus.utils import config as pybliometrics_config
pybliometrics_config['Authentication']['APIKey'] = "MYKEY"

both before

from pybliometrics.scopus import AuthorSearch
from pybliometrics.scopus.exception import Scopus401Error
import pybliometrics

and after it.

But pybliometrics is still using the API key from config.ini.

I know because I get a "Scopus401Error: Invalid API Key" error, and I have modified pybliometrics/scopus/utils/get_content.py by adding

print(f"KEYS={KEYS}")

after

from pybliometrics.scopus.utils.startup import _throttling_params, KEYS

in the get_content function, and it is printing the API key in the config file.

@Michael-E-Rose
Copy link
Contributor

That's correct, module startup.py reads the configuration file and stores the keys in KEYS. It's not intended to set the keys on runtime.

Why don't you just change the keys in the configuration file?

@raffaem
Copy link
Contributor Author

raffaem commented Dec 24, 2021

Why don't you just change the keys in the configuration file?

Because it's a shared computer and the documentation says I can change them from code

@Michael-E-Rose
Copy link
Contributor

You probably refer to https://pybliometrics.readthedocs.io/en/stable/configuration.html#runtime, right?

It used to be possible to assign keys at runtime, but since I implemented throttling it was too difficult to maintain this feature (especially while maintaining a smooth compilation on rtfd.io).

But what should work is to change the location of the configuration at runtime (but before importing pybliometrics) as in https://pybliometrics.readthedocs.io/en/stable/configuration.html#custom-location
This should give you the possibility to have distinct keys on the same installation. The only downside is that you would have to write the same directories in different configuration files.

@raffaem
Copy link
Contributor Author

raffaem commented Dec 25, 2021

You probably refer to https://pybliometrics.readthedocs.io/en/stable/configuration.html#runtime, right?

Yes

It used to be possible to assign keys at runtime, but since I implemented throttling it was too difficult to maintain this feature (especially while maintaining a smooth compilation on rtfd.io).

Let's change the docs if that is no longer the case :)

But what should work is to change the location of the configuration at runtime (but before importing pybliometrics) as in https://pybliometrics.readthedocs.io/en/stable/configuration.html#custom-location This should give you the possibility to have distinct keys on the same installation.

ok, I'll try that. For the moment I achieved what I had to do.

The only downside is that you would have to write the same directories in different configuration files.

Why, if I want to keep the cache separate?

@Michael-E-Rose
Copy link
Contributor

For now I the documentation make clear that one cannot set keys at runtime. Maybe in future this will be possible.

raffaem pushed a commit to raffaem/pybliometrics that referenced this issue Nov 24, 2022
@claell
Copy link

claell commented Aug 17, 2023

Seems like duplicate (or related to) #161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants