twitter-api-client icon indicating copy to clipboard operation
twitter-api-client copied to clipboard

json error when using pagination

Open yao177 opened this issue 1 year ago • 3 comments

When I use pagination of twitter followers, it shows Cannot parse JSON response 'str' object has no attribute 'json'. I think it's about pagination's merge.

yao177 avatar Sep 22 '23 08:09 yao177

I found that exception is in util.py:

def get_json(res: list[Response], **kwargs) -> list:
    cursor = kwargs.get('cursor')
    temp = res
    if any(isinstance(r, (list, tuple)) for r in res):
        temp = flatten(res)
    results = []
    for r in temp:
        try:
            data = r.json()
            if cursor:
                results.append([data, cursor])
            else:
                results.append(data)
        except Exception as e:
            print('Cannot parse JSON response', e)
    return results

yao177 avatar Sep 24 '23 07:09 yao177

I find that the cursor is considered as element in temp.

I print temp:

temp: [<Response [200 OK]>, '1719229905266413416|1705851066710490964']

But cursor cannot trans to json so cause this exception.

yao177 avatar Sep 24 '23 07:09 yao177

Same problem

DhiaHan avatar Sep 08 '24 16:09 DhiaHan