diff --git a/richcontext/scholapi/scholapi.py b/richcontext/scholapi/scholapi.py index f120ddb..1de8646 100755 --- a/richcontext/scholapi/scholapi.py +++ b/richcontext/scholapi/scholapi.py @@ -382,11 +382,16 @@ def publication_lookup (self, identifier): t0 = time.time() url = self._get_api_url(identifier) - meta = json.loads(requests.get(url).text) + response = requests.get(url) + if response.status_code == requests.codes.ok: + meta = json.loads(response.text) if not meta or len(meta) < 1 or "error" in meta: meta = None - + elif "message" in meta: + message = meta["message"] + meta = None + timing = self._mark_elapsed_time(t0) return _ScholInfraResponse_SemanticScholar(self, meta, timing, message) diff --git a/test.py b/test.py index bd89f33..4682536 100755 --- a/test.py +++ b/test.py @@ -404,6 +404,13 @@ def test_semantic_publication_lookup (self): response = source.publication_lookup(doi) self.assertTrue(response.meta == None) + # another error case + doi = "10.1641/0006-3568(2005)055[0879:EITLSA]2.0.CO;2" + + if source.has_credentials(): + response = source.publication_lookup(doi) + self.assertTrue(response.meta == None) + ###################################################################### ## Misc. family of APIs