thedev132 / Osintgram

Osintgram is a OSINT tool on Instagram. It offers an interactive shell to perform analysis on Instagram account of any users by its nickname
GNU General Public License v3.0
20 stars 0 forks source link

401 unauthorized when target is another account - followers command #6

Closed TastingSunsets closed 9 months ago

TastingSunsets commented 10 months ago

Hi

I log in with a "secondary" instagram account to gather data about my main account, @tastingsunsets. When performing the followers command, I get a 401 unauthorized error, followed by instagrapi.exceptions.PleaseWaitFewMinutes. The target account has 3k+ followers. When I perform the same command on the account that I log in with, the command works. This secondary account has 800 followers. The secondary account follows @tastinsunsets (which is a public account anyways).

Here's the complete traceback for when the command fails:

Run a command: followers Searching for target followers (this may take a while) ... Traceback (most recent call last): File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 168, in _send_public_request response.raise_for_status() File "/opt/homebrew/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%2251675445256%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Afalse%2C%22first%22%3A12%7D&query_hash=5aefa9893005572d237da5068082d8d5

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/user.py", line 784, in user_followers users = self.user_followers_gql(user_id, amount) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/user.py", line 689, in user_followersgql users, = self.user_followers_gql_chunk(str(user_id), amount) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/user.py", line 655, in user_followers_gql_chunk data = self.public_graphql_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 240, in public_graphql_request body_json = self.public_request( ^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 123, in public_request raise e File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/public.py", line 100, in public_request return self._send_public_request(url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/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%2251675445256%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Afalse%2C%22first%22%3A12%7D&query_hash=5aefa9893005572d237da5068082d8d5

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/private.py", line 360, in _send_private_request response.raise_for_status() File "/opt/homebrew/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://i.instagram.com/api/v1/friendships/51675445256/followers/?max_id=&count=200&rank_token=8021155557_3df401ed-a28c-4a57-8e6a-1ffd4920f1c5&search_surface=follow_list_page&query=&enable_groups=true

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/tasting.sunsets/sandbox/osint/Osintgram/main.py", line 173, in _cmd() File "/Users/tasting.sunsets/sandbox/osint/Osintgram/src/Osintgram.py", line 306, in get_followers data = client.user_followers(str(self.target_id)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/user.py", line 788, in user_followers users = self.user_followers_v1(user_id, amount) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/user.py", line 755, in user_followersv1 users, = self.user_followers_v1_chunk(str(user_id), amount) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/user.py", line 717, in user_followers_v1_chunk result = self.private_request( ^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/private.py", line 542, in private_request raise e File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/private.py", line 527, in private_request self._send_private_request(endpoint, kwargs) File "/opt/homebrew/lib/python3.11/site-packages/instagrapi/mixins/private.py", line 383, in _send_private_request raise PleaseWaitFewMinutes(e, response=e.response, last_json) instagrapi.exceptions.PleaseWaitFewMinutes: Please wait a few minutes before you try again.

Any insights in how to fix this? Great tool by the way!

thedev132 commented 10 months ago

That error only appears when Instagram has forced the user account to wait before sending more requests. I encounter that error sometimes too when I'm logging in a lot of times (mostly cuz I'm testing if the code will break or not) Also, it's logging in twice with 2 different libraries. I'm working on using only one in the future and using sessions to further allow you to not have to relogin everytime.

thedev132 commented 9 months ago

The newest push has a sessions feature which will allow you to login in to the same session multiple times