NASA-Planetary-Science/sbpy

`sbpy.bib` ADS query problem due to `ads` module being out of date?

jianyangli opened this issue · 3 comments

High-level problem description
bib.to_text() and similar functions that involve ADS query returns ads.exceptions.APIResponseError.

What did you do?

from sbpy import bib
bib.track()
print(bib.to_text())

What did you expect?
Print out a text string with reference information retrieved from ADS.

What did really happen?
A ads.exceptions.APIResponseError exception is issued.

/Users/jyli/.env/work/lib/python3.8/site-packages/ads/base.py:135: RuntimeWarning: No token found
warnings.warn("No token found", RuntimeWarning)

APIResponseError Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 print(bib.to_text())

File /Volumes/Pegasus/Work/Git/sbpy/sbpy/bib/core.py:254, in to_text(filter)
250 with warnings.catch_warnings():
251 # warnings.filterwarnings('error')
252 try:
253 # request needed fields to avoid lazy loading
--> 254 paper = list(
255 ads.SearchQuery(
256 bibcode=citation,
257 fl=['first_author', 'author', 'volume',
258 'pub', 'issue', 'page', 'year']
259 ))[0]
260 except (IndexError, Warning, RuntimeWarning) as e:
261 # if query failed,
262 output += ' {:s}\n'.format(citation)

File ~/.env/work/lib/python3.8/site-packages/ads/search.py:501, in SearchQuery.next(self)
498 # Allow immediate iteration without forcing a user to call .execute()
499 # explicitly
500 if self.response is None:
--> 501 self.execute()
503 try:
504 cur = self._articles[self.__iter_counter]

File ~/.env/work/lib/python3.8/site-packages/ads/search.py:532, in SearchQuery.execute(self)
526 def execute(self):
527 """
528 Sends the http request implied by the self.query
529 In addition, set up the request such that we can call next()
530 to provide the next page of results
531 """
--> 532 self.response = SolrResponse.load_http_response(
533 self.session.get(self.HTTP_ENDPOINT, params=self.query)
534 )
536 # ADS will apply a ceiling to 'rows' and re-write the query
537 # This code checks if that happened by comparing the reponse
538 # "rows" with what we sent in our query
539 # references andycasey/ads#45
540 recv_rows = int(self.response.responseHeader.get("params", {}).get("rows"))

File ~/.env/work/lib/python3.8/site-packages/ads/base.py:94, in APIResponse.load_http_response(cls, http_response)
89 """
90 This method should return an instantiated class and set its response
91 to the requests.Response object.
92 """
93 if not http_response.ok:
---> 94 raise APIResponseError(http_response.text)
95 c = cls(http_response)
96 c.response = http_response

APIResponseError: '{\n "error": "Unauthorized"\n}\n'

I think this is due to ads being out of date. The previous ads update on the GitHub repository was 13 months ago. But someone should check and see if this can be fixed on the sbpy end.

Provide information on your environment:
macOS-10.15.7-x86_64-i386-64bit
sbpy == '0.2.3.dev223+g9eb0523'
ads == '0.12.3'

Hi @jianyangli , it looks like you are missing an ADS API token. Is that the case? We have some notes on it at the top of: https://sbpy.readthedocs.io/en/latest/sbpy/bib.html

Yes you are right @mkelley . Now everything works well. Thanks.