sckott / habanero

client for Crossref search API
https://habanero.readthedocs.io
MIT License
207 stars 30 forks source link

Feature Request #92

Closed chackoge closed 3 years ago

chackoge commented 3 years ago

Hello- when submitting a list of DOIs to content_negotiation as below, if one of the DOIs isn't found no data is returned and an error is returned. Is there a way to return 'doi not found' and process the rest of the data? Thanks

Python 3.8.2 (default, Nov 4 2020, 21:23:28) habanero 0.7.4

from habanero import cn print(testlist)

['10.1126/science.169.3946.635', '10.1162/qss_a_00007', '10.1126/science.169.3946.637'] # the third DOI doesn't exist

cn.content_negotiation(ids = kws[0:2],format='bibtex')

['@article{Frank_1970,\n\tdoi = {10.1126/science.169.3946.635},\n\turl = {https://doi.org/10.1126%2Fscience.169.3946.635},\n\tyear = 1970,\n\tmonth = {aug},\n\tpublisher = {American Association for the Advancement of Science ({AAAS})},\n\tvolume = {169},\n\tnumber = {3946},\n\tpages = {635--641},\n\tauthor = {H. S. Frank},\n\ttitle = {The Structure of Ordinary Water: New data and interpretations are yielding new insights into this fascinating substance},\n\tjournal = {Science}\n}', '@article{Bradley_2020,\n\tdoi = {10.1162/qss_a_00007},\n\turl = {https://doi.org/10.1162%2Fqss_a_00007},\n\tyear = 2020,\n\tmonth = {feb},\n\tpublisher = {{MIT} Press - Journals},\n\tvolume = {1},\n\tnumber = {1},\n\tpages = {264--276},\n\tauthor = {James Bradley and Sitaram Devarakonda and Avon Davey and Dmitriy Korobskiy and Siyu Liu and Djamil Lakhdar-Hamina and Tandy Warnow and George Chacko},\n\ttitle = {Co-citations in context: Disciplinary heterogeneity is relevant},\n\tjournal = {Quantitative Science Studies}\n}']

cn.content_negotiation(ids = kws[0:3],format='bibtex')

HTTPError Traceback (most recent call last)

in ----> 1 cn.content_negotiation(ids = kws[0:3],format='bibtex') /opt/anaconda3/lib/python3.8/site-packages/habanero/cn/cn.py in content_negotiation(ids, format, style, locale, url, **kwargs) 80 if url is None: 81 url = cn_base_url ---> 82 return CNRequest(url, ids, format, style, locale, **kwargs) /opt/anaconda3/lib/python3.8/site-packages/habanero/cnrequest.py in CNRequest(url, ids, format, style, locale, **kwargs) 29 coll = [] 30 for i in range(len(ids)): ---> 31 tt = make_request(url, ids[i], format, style, locale, **kwargs) 32 coll.append(tt) 33 /opt/anaconda3/lib/python3.8/site-packages/habanero/cnrequest.py in make_request(url, ids, format, style, locale, **kwargs) 52 53 # Raise an HTTPError if the status code of the response is 4XX or 5XX ---> 54 response.raise_for_status() 55 56 # set encoding /opt/anaconda3/lib/python3.8/site-packages/requests/models.py in raise_for_status(self) 939 940 if http_error_msg: --> 941 raise HTTPError(http_error_msg, response=self) 942 943 def close(self): HTTPError: 404 Client Error: for url: https://doi.org/10.1126/science.169.3946.637
sckott commented 3 years ago

thanks for the issue @chackoge

see also https://github.com/sckott/habanero/issues/69

reinstall from here and try again, let me know if it works for you - updated docs here https://habanero.readthedocs.io/en/latest/modules/cn.html#module-habanero with info on warnings

chackoge commented 3 years ago

Works great thank you very much. I like throwing an error when only a single DOI is provided. It's a great client. Being new to Python I ran pip install --force-reinstall habanero a couple of times to no effect before realizing that I needed to run pip install --force-reinstall git+git://github.com/sckott/habanero.git#egg=habanero I did see #69 but since it related to works rather then cn, I wasn't sure whether to create a new request but eventually did.

sckott commented 3 years ago

Was just pinging the other issue as a note to myself so I don't forget about them covering the same topic.

I don't understand very well install from github for python, so I can't help much there - so glad that worked for you.