instagrapi
instagrapi copied to clipboard
instagrapi.exceptions.ClientUnauthorizedError: 401 Client Error: Unauthorized for url: [BUG]
To Reproduce
from instagrapi import Client
import os
def login(username, password):
cl = Client()
cl.delay_range = [60, 70]
if os.path.exists(f"settings({username}).json"):
cl.load_settings(f"settings({username}).json")
if cl.login(username=username, password=password):
cl.dump_settings(f"settings({username}).json")
print("Login successful")
# Add your code here to run after successful login
yo = cl.user_followers_gql_chunk("xxx", 0, "None")
print(yo)
return cl
else:
print("Login failed")
cl = login('xxxx', 'xxxx')
Traceback
Traceback (most recent call last):
File "/home/user/.local/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 168, in _send_public_request
response.raise_for_status()
File "/usr/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://www.instagram.com/graphql/query/?variables=%7B%22id%22%3A%2252218558877%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Afalse%2C%22first%22%3A12%2C%22after%22%3A%22None%22%7D&query_hash=5aefa9893005572d237da5068082d8d5
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/shjee/Desktop/insta/main.py", line 22, in <module>
cl = login('xxxx', 'xxxx')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/Desktop/insta/main.py", line 14, in login
yo = cl.user_followers_gql_chunk("xxxx", 0, "None")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.11/site-packages/instagrapi/mixins/user.py", line 664, in user_followers_gql_chunk
data = self.public_graphql_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 240, in public_graphql_request
body_json = self.public_request(
^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 123, in public_request
raise e
File "/home/user/.local/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 100, in public_request
return self._send_public_request(url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/shjee/.local/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 191, in _send_public_request
raise ClientUnauthorizedError(e, response=e.response)
instagrapi.exceptions.ClientUnauthorizedError: 401 Client Error: Unauthorized for url: https://www.instagram.com/graphql/query/?variables=%7B%22id%22%3A%2252218558877%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Afalse%2C%22first%22%3A12%2C%22after%22%3A%22None%22%7D&query_hash=5aefa9893005572d237da5068082d8d5
Expected behavior to get all the users followers
Desktop (please complete the following information):
- OS: Alpine Linux
- Python version 3.11
- instagrapi version latest
Same problem here.
use session, do not login every run with your code and use high quality proxy, account
Same problem using client.user_followers_gql_chunk(user_id, max_amount=200, end_cursor=current_cursor)
in a for loop with sleep. In second iteration I get the error