Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scraper when receives <Response [429 Too Many Requests]> returns None which causes Cannot parse JSON response 'NoneType' object has no attribute 'json' inside of 'get_json' #234

Open
vxoid opened this issue Sep 14, 2024 · 0 comments

Comments

@vxoid
Copy link

vxoid commented Sep 14, 2024

pretty easy fix here

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:
            if r is None: # Add this check here
                continue
            
            data = r.json()
            if cursor:
                results.append([data, cursor])
            else:
                results.append(data)
        except Exception as e:
            print('Cannot parse JSON response', e)
            print(dedent(f'''{ORANGE}
            Checklist:
                1. Log-in via the browser and confirm your account is not blocked, or has pending security challenges.
                2. Copy the `ct0` and `auth_token` cookies from the browser.
                3. Re-run your program using these new cookies.
            {RESET}'''))
    return results
vxoid added a commit to vxoid/twitter-api-client that referenced this issue Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant