Skip to content

curl working but not request #103

@joelczinn

Description

@joelczinn

Hello,

Thanks so much for this service. I would love to take advantage of it, but I'm running into an authorization issue, it seems.

I would expect the following code to work:

import requests
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:TOKEN'},
    data=bibcodes)
print(r.text)

However, the result is:

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

However, the equivalent request via curl:

curl 'https://api.adsabs.harvard.edu/v1/search/bigquery?q=*:*&fl=bibcode'  -X 'POST' -H 'Authorization: Bearer TOKEN' -H 'Content-Type: big-query/csv' -d $'bibcode\n1907AN....174...59.\n1908PA.....16..445.\n1989LNP...334..242S'

works and returns:

{
  "responseHeader":{
    "status":0,
    "QTime":31,
    "params":{
      "q":"*:*",
      "fl":"bibcode",
      "start":"0",
      "internal_logging_params":"X-Amzn-Trace-Id=Root=1-64fbb58b-52d35276622d99767e24944b",
      "fq":"{!bitset}",
      "rows":"10",
      "wt":"json"}},
  "response":{"numFound":3,"start":0,"docs":[
      {
        "bibcode":"1989LNP...334..242S"},
      {
        "bibcode":"1907AN....174...59."},
      {
        "bibcode":"1908PA.....16..445."}]
  }}

requests is v2.31.0 and Python is v3.8.6.

Thanks in advance for the help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions