adsabs / adsabs-dev-api

Developer API service description and example client code
163 stars 58 forks source link

401 Unauthorized #32

Open borisrev opened 7 years ago

borisrev commented 7 years ago

Using the example Python snippet:

bibcodes="bibcode\n1907AN....174...59.\n1908PA.....16..445.\n1989LNP...334..242S"
r = requests.post('https://api.adsabs.harvard.edu/v1/search/bigquery', 
       params={'q':'*:*', 'wt':'json', 'fq':'{!bitset}', 'fl':'bibcode'}, 
       headers={'Authorization': 'Bearer: mytokenhere'},
       data=bibcodes)

I get a 401 unathorized response. I can do a curl request with the same token, and it works fine.

Thanks for all the great work and in advance for any help.

ghost commented 7 years ago

Hi Boris, It's a problem of our documentation, sorry about that. First, the 'q' parameter shouldn't be empty, it needs to contain a valid query - you can use ':' - and finally, there is an extra space in the Authorization header. Please see below for an example:

In [7]: r = requests.post('https://api.adsabs.harvard.edu/v1/search/bigquery ', ...: params={'q':':', 'wt':'json', 'fq':'{!bitset}', 'fl':'bibcode'}, ...: headers={'Authorization': 'Bearer:' + token}, ...: data=bibcodes)

In [8]: r.status_code Out[8]: 200

In [9]: r = requests.post('https://api.adsabs.harvard.edu/v1/search/bigquery ', ...: params={'q':':', 'wt':'json', 'fq':'{!bitset}', 'fl':'bibcode'}, ...: headers={'Authorization': 'Bearer: ' + token}, ...: data=bibcodes)

In [10]: r.status_code Out[10]: 401

I'll fix the documentation.

Thanks!

Roman

On Tue, Jun 13, 2017 at 3:29 PM, Boris Revechkis notifications@github.com wrote:

Using the example Python snippet:

bibcodes="bibcode\n1907AN....174...59.\n1908PA.....16..445. \n1989LNP...334..242S" r = requests.post('https://api.adsabs.harvard.edu/v1/search/bigquery', params={'q':':', 'wt':'json', 'fq':'{!bitset}', 'fl':'bibcode'}, headers={'Authorization': 'Bearer: mytokenhere'}, data=bibcodes)

I get a 401 unathorized response. I can do a curl request with the same token, and it works fine.

Thanks for all the great work and in advance for any help.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/adsabs/adsabs-dev-api/issues/32, or mute the thread https://github.com/notifications/unsubscribe-auth/AHURkZbyqcXtBusdvAFpG9buUmEOsSSjks5sDuMKgaJpZM4N497I .

borisrev commented 7 years ago

Thank you!