Paginating through lists - "error": "Couldn't authenticate you" | Community
Skip to main content

Paginating through lists - "error": "Couldn't authenticate you"

  • June 29, 2023
  • 5 replies
  • 0 views

I'm trying to get a list of users through the API and even using the exact code from the documentation its not working. I'm using Python to make the request and when I run this code 

while url:
    response = requests.get(url, auth=auth, params=params)
    data = response.json()

    # do something with the data
    for user in data['users']:
        print(user['name'])

    if data['meta']['has_more']:
        params['page[after]'] = data['meta']['after_cursor']
    else:
        url = None

 

I get 'error': "Couldn't authenticate you".

 

It only breaks when it's in the loop, if I try to pull a single page outside the loop it works no issue, but if I try to loop it I get nothing.  

Any assistance with this error is appreciated. 

 

5 replies

Hi Kyle,
 
While in the loop, do you also get a successful response from the first request?  Or does the first request fail with this error?

  • Author
  • June 30, 2023

The first request is successful, whether I start with the first or second page doesn't matter, but the second one fails every time.


Hi Kyle,
 
I'm not able to reproduce this my testing.  Is it OK if I create a ticket to work with you on the specific details of your test?

  • Author
  • July 12, 2023

I did eventually get this worked out.  I made a couple of smaller changes all at the same time so I'm not 100% sure what the issue was but the most likely culprit I think was using single quotes when setting the URL variable rather than double quotes.  

So thank you for looking into this but it is resolved now.


No problem.  I'm glad to hear that you got it sorted.