From aff46b273dfe5b73d4e12343e79c75d84c38ceaf Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Thu, 11 Feb 2016 15:32:05 +0100 Subject: [PATCH] Fix an error when no publications was returned in doi.get_oa_policy() --- libbmc/__init__.py | 2 +- libbmc/doi.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libbmc/__init__.py b/libbmc/__init__.py index 28e9f10..b42a0d5 100644 --- a/libbmc/__init__.py +++ b/libbmc/__init__.py @@ -7,7 +7,7 @@ __valid_identifiers__ = [] from . import bibtex, doi, fetcher, isbn # noqa from . import citations, papers, repositories # noqa -__version__ = "0.1.2" +__version__ = "0.1.3.1" __all__ = [ "bibtex", "doi", "fetcher", "isbn", diff --git a/libbmc/doi.py b/libbmc/doi.py index f3a4b8d..bdd9f1e 100644 --- a/libbmc/doi.py +++ b/libbmc/doi.py @@ -157,6 +157,9 @@ def get_oa_policy(doi): >>> tmp = get_oa_policy('10.1209/0295-5075/111/40005'); (tmp["published"], tmp["preprint"], tmp["postprint"], tmp["romeo_id"]) ('can', 'can', 'can', '1896') + + >>> get_oa_policy('10.1215/9780822387268') is None + True """ try: r = requests.get("%s%s" % (DISSEMIN_API, doi)) @@ -166,7 +169,8 @@ def get_oa_policy(doi): return ([i for i in result["paper"]["publications"] if i["doi"] == doi][0])["policy"] - except (AssertionError, ValueError, KeyError, RequestException): + except (AssertionError, ValueError, + KeyError, RequestException, IndexError): return None