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

Instagram 'Redirected to login page' error #165

Closed
raul27868 opened this issue Dec 8, 2020 · 3 comments
Closed

Instagram 'Redirected to login page' error #165

raul27868 opened this issue Dec 8, 2020 · 3 comments
Labels
bug Something isn't working module:instagram upstream wontfix This will not be worked on

Comments

@raul27868
Copy link

For snscrape --max-results 50 instagram-user "user":

2020-12-08 10:58:55.184 CRITICAL snscrape._cli Dumped stack and locals to /tmp/snscrape_locals_q6gn6xra
Traceback (most recent call last):
File "/usr/local/bin/snscrape", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.8/site-packages/snscrape/_cli.py", line 270, in main
for i, item in enumerate(scraper.get_items(), start = 1):
File "/usr/local/lib/python3.8/site-packages/snscrape/modules/instagram.py", line 137, in get_items
r = self._initial_page()
File "/usr/local/lib/python3.8/site-packages/snscrape/modules/instagram.py", line 111, in _initial_page
raise snscrape.base.ScraperException('Redirected to login page')
snscrape.base.ScraperException: Redirected to login page

@JustAnotherArchivist
Copy link
Owner

That means that your IP has been semi-banned. Instagram has ridiculous rate limits for anonymous users on profile pages to the point that you can easily trigger them with a few clicks on profile links. They also ban all IP ranges from major server providers. To my knowledge, the only way around it is logging in, but I have no intentions of adding any sort of login to snscrape (cf. #23 and #50).

@TheTechRobo
Copy link
Contributor

I now seem to be getting this instead:

/m/t/2/a/insta ❯❯❯ snscrape --progress --jsonl instagram-user mankai_company_en >> insta.jsonl
Scraping, 100 results so far
2022-03-30 17:56:34.337  ERROR  snscrape.base  Error retrieving https://www.instagram.com/graphql/query/?query_hash=f2405b236d85e8296cf30347c9f08c2a&variables=%7B%22id%22:%2221446477225%22,%22first%22:50,%22after%22:%22QVFCOHlxeVFKaC13RDVuNVJLN284eGtKWEhJdXdPU1lnNklIR0FqaHJud3JkdG9MYndFLUlRWElNRWFBZVI2UlhSV0JYZjNnNGJxRUNMUlgtWFViVnVLVg==%22%7D: invalid JSON (JSONDecodeError('Expecting value: line 1 column 1 (char 0)'))
2022-03-30 17:56:34.337  CRITICAL  snscrape.base  4 requests to https://www.instagram.com/graphql/query/?query_hash=f2405b236d85e8296cf30347c9f08c2a&variables=%7B%22id%22:%2221446477225%22,%22first%22:50,%22after%22:%22QVFCOHlxeVFKaC13RDVuNVJLN284eGtKWEhJdXdPU1lnNklIR0FqaHJud3JkdG9MYndFLUlRWElNRWFBZVI2UlhSV0JYZjNnNGJxRUNMUlgtWFViVnVLVg==%22%7D failed, giving up.
2022-03-30 17:56:34.398  CRITICAL  snscrape._cli  Dumped stack and locals to /tmp/snscrape_locals_eww5_2ip
Traceback (most recent call last):
  File "/home/thetechrobo/.local/bin/snscrape", line 8, in <module>
    sys.exit(main())
  File "/home/thetechrobo/.local/lib/python3.9/site-packages/snscrape/_cli.py", line 308, in main
    for i, item in enumerate(scraper.get_items(), start = 1):
  File "/home/thetechrobo/.local/lib/python3.9/site-packages/snscrape/modules/instagram.py", line 131, in get_items
    r = self._get(f'https://www.instagram.com/graphql/query/?query_hash={self._queryHash}&variables={variables}', headers = headers, responseOkCallback = self._check_json_callback)
  File "/home/thetechrobo/.local/lib/python3.9/site-packages/snscrape/base.py", line 218, in _get
    return self._request('GET', *args, **kwargs)
  File "/home/thetechrobo/.local/lib/python3.9/site-packages/snscrape/base.py", line 214, in _request
    raise ScraperException(msg)
snscrape.base.ScraperException: 4 requests to https://www.instagram.com/graphql/query/?query_hash=f2405b236d85e8296cf30347c9f08c2a&variables=%7B%22id%22:%2221446477225%22,%22first%22:50,%22after%22:%22QVFCOHlxeVFKaC13RDVuNVJLN284eGtKWEhJdXdPU1lnNklIR0FqaHJud3JkdG9MYndFLUlRWElNRWFBZVI2UlhSV0JYZjNnNGJxRUNMUlgtWFViVnVLVg==%22%7D failed, giving up.

Locals: https://transfer.archivete.am/XBaoT/snscrape-locals

@JustAnotherArchivist
Copy link
Owner

Confirmed, triggered it after a while, it's a redirect to the login page. The above commit now detects this and raises an exception as in the first comment instead of this obscure generic error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module:instagram upstream wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants