diff --git a/pyalex/api.py b/pyalex/api.py index 2590dfb..8ef3407 100644 --- a/pyalex/api.py +++ b/pyalex/api.py @@ -44,6 +44,10 @@ def invert_abstract(inv_index): return " ".join(map(lambda x: x[0], sorted(l, key=lambda x: x[1]))) +class QueryError(ValueError): + pass + + class OpenAlexEntity(dict): pass @@ -139,6 +143,20 @@ def _get_multi_items(self, record_list): return self.filter(openalex_id="|".join(record_list)).get() + def __getattr__(self, key): + + if key == "groupby": + raise AttributeError( + "Object has no attribute 'groupby'. " + "Did you mean 'group_by'?") + + if key == "filter_search": + raise AttributeError( + "Object has no attribute 'filter_search'. " + "Did you mean 'search_filter'?") + + return getattr(self, key) + def __getitem__(self, record_id): if isinstance(record_id, list): @@ -177,9 +195,13 @@ def get(self, return_meta=False, page=None, per_page=None, cursor=None): res = requests.get( url, headers={"User-Agent": "pyalex/" + __version__, "email": config.email} ) - res.raise_for_status() res_json = res.json() + if res.status_code == 403 and "query parameters" in res_json["error"]: + raise QueryError(res_json["message"]) + + res.raise_for_status() + # group-by or results page if "group-by" in self.params: results = res_json["group_by"]