pybliometrics-dev / pybliometrics

Python-based API-Wrapper to access Scopus
https://pybliometrics.readthedocs.io/en/stable/
Other
420 stars 129 forks source link

ImportError: cannot import name 'KEYS' from 'pybliometrics.scopus.utils.startup' (/usr/local/lib/python3.7/dist-packages/pybliometrics/scopus/utils/startup.py) #196

Closed etsern closed 3 years ago

etsern commented 3 years ago

Bug report I am using pybliometrics in googlecolab. I am using Scopus Api key with tokken. Everything was working fine, but this week the following error appears: ImportError: cannot import name 'KEYS' from 'pybliometrics.scopus.utils.startup' (/usr/local/lib/python3.7/dist-packages/pybliometrics/scopus/utils/startup.py). It appears, when I use ScopusSearch.

How to solve this problem?

/usr/local/lib/python3.7/dist-packages/pybliometrics/scopus/utils/get_content.py in get_content(url, api, params, **kwds)
     53     from simplejson import JSONDecodeError
     54 
---> 55     from pybliometrics.scopus.utils.startup import _throttling_params, KEYS
     56 
     57     # Set header, params and proxy

ImportError: cannot import name 'KEYS' from 'pybliometrics.scopus.utils.startup' (/usr/local/lib/python3.7/dist-packages/pybliometrics/scopus/utils/startup.py)
Michael-E-Rose commented 3 years ago

Which pybliometrics.__version__ are you using? 3.0.0?

etsern commented 3 years ago

pybliometrics-3.0.0

Michael-E-Rose commented 3 years ago

And how does your config.ini look like? Is it somehow similar to what's described in https://pybliometrics.readthedocs.io/en/stable/configuration.html?

trifen commented 3 years ago

I had the same problem. I have solved this problem by removing the "try-except" structure in "startup.py". Specifically, I replace the following code:

try:
    config = configparser.ConfigParser()
    config.optionxform = str
    config.read(CONFIG_FILE)
    # Parse keys with fixture for RTFD.io
    try:
        KEYS = [k.strip() for k in config.get('Authentication', 'APIKey').split(",")]
    except configparser.NoSectionError:
        pass
except FileNotFoundError:
    import warnings
    text = "pybliometrics did not find a configuration file.  Please issue "\
          "pybliometrics.scopus.utils.create_config() to start the process "\
          "which guides you through the generation of the configuration "\
          "file or read https://pybliometrics.readthedocs.io/en/stable/configuration.html."
    warnings.warn(text, UserWarning)

with the code:

config = configparser.ConfigParser()
config.optionxform = str
config.read(CONFIG_FILE)    
KEYS = [k.strip() for k in config.get('Authentication', 'APIKey').split(",")]
Michael-E-Rose commented 3 years ago

I remember in 3.0.0 I caused a bug that prevented new users to properly run pybliometrics the first time. It's not occurring anymore, and I think it's because of 71a022d5ba6ebceb6ab271d63cbefff23f1767a0 possibly in conjunction with c05526b3b979abc6bb0a23938c7c1125f0713e3b.

fahmij8 commented 3 years ago

@Michael-E-Rose Please re-open this issue, it seems like if you try this using python 3.7 or higher this error will occur and it's bugging me.

Michael-E-Rose commented 3 years ago

Reopening around doesn't solve it. What version are you using, @fahmij8 ?

fahmij8 commented 3 years ago

I believe it's the latest version @Michael-E-Rose

Michael-E-Rose commented 3 years ago

It clearly says you're on 3.0.1.

I suspect your error is related to the fact that you're running on a notebook. Let met tell you, it won't work anyways, for reasons outlined in https://pybliometrics.readthedocs.io/en/stable/access.html (unless you use InstToken, which is rare).

Do you have the possibility to use a local environment with your institution's VPN?

fahmij8 commented 3 years ago

I see, yup I do. Thanks for the assistance!

Michael-E-Rose commented 3 years ago

The import failure is essentially due to a fixture I implement to automatically generate the documentation. I bet the import on google colab fails for the same reason. I might find time later this week to try another fixture, but in any case, the colab doesn't provide the necessary access rights.

etsern commented 3 years ago

@fahmij8 As a result, I use the previous versions of pybliometrics. @Michael-E-Rose Even with tokens, the new version doesn't work in colab.