subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.38k stars 685 forks source link

[BUG] 401 Client Error, 403 Error, Login required. #1371

Closed NicoRulli closed 1 year ago

NicoRulli commented 1 year ago

Describe the bug My code is supposed to log into instagram daily and post something. it worked for a couple days then stopped due to instagram preventing new logins from my code. I just downloaded a free proxy and have my IP set to the same one. Now when I run it, I get the request to my email that I have to put a code in. Okay for now However, I'm still getting login issues.

Traceback Traceback (most recent call last): File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/public.py", line 136, in _send_public_request response.raise_for_status() File "/Users/nicolasrulli/Library/Python/3.8/lib/python/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%22shortcode%22%3A%22CqoxZb9P4Vt%22%2C%22child_comment_count%22%3A3%2C%22fetch_comment_count%22%3A40%2C%22parent_comment_count%22%3A24%2C%22has_threaded_comments%22%3Afalse%7D&query_hash=477b65a610463740ccdb83135b2014db

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/media.py", line 259, in media_info media = self.media_info_gql(media_pk) File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/media.py", line 204, in media_info_gql data = self.public_graphql_request( File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/public.py", line 216, in public_graphql_request body_json = self.public_request( File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/public.py", line 97, in public_request raise e File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/public.py", line 74, in public_request return self._send_public_request(url, **kwargs) File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/public.py", line 169, in _send_public_request raise ClientError(e, response=e.response) instagrapi.exceptions.ClientError: 401 Client Error: Unauthorized for url: https://www.instagram.com/graphql/query/?variables=%7B%22shortcode%22%3A%22CqoxZb9P4Vt%22%2C%22child_comment_count%22%3A3%2C%22fetch_comment_count%22%3A40%2C%22parent_comment_count%22%3A24%2C%22has_threaded_comments%22%3Afalse%7D&query_hash=477b65a610463740ccdb83135b2014db

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/private.py", line 313, in _send_private_request response.raise_for_status() File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/requests/models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://i.instagram.com/api/v1/media/3073923997964928365/info/

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "file2.py", line 153, in media_type = client.media_info(MLPK).dict()['media_type'] File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/media.py", line 269, in media_info media = self.media_info_v1(media_pk) File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/media.py", line 236, in media_info_v1 raise e File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/media.py", line 230, in media_info_v1 result = self.private_request(f"media/{media_pk}/info/") File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/private.py", line 461, in private_request raise e File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/private.py", line 446, in private_request self._send_private_request(endpoint, kwargs) File "/Users/nicolasrulli/Library/Python/3.8/lib/python/site-packages/instagrapi/mixins/private.py", line 337, in _send_private_request raise LoginRequired(response=e.response, last_json) instagrapi.exceptions.LoginRequired: login_required

What can I do to get it to login properly? I don't fully understand the relogin stuff. Is there a line of code I can run that returns a boolean to see if I'm actually logged in? How can I tell if I'm actually logged in and if I'm not, how can I login again//relogin?

Also, should I be logging out at the end of my code? If so where is the code for that?

Thanks!

Desktop (please complete the following information):

florifull commented 1 year ago

I'm getting this same issue..

arda1984 commented 1 year ago

same

chrisbuetti commented 1 year ago

What works for me is to delete my settings (if you were passing them in) and login in from new, but I'm struggling to properly but this in a try/except

NicoRulli commented 1 year ago

@chrisbuetti I don't have settings to pass in. Can you help me with that? I don't understand the repositories / how to make a settings file. I already lost an account with 14k followers so I'm starting over and really want to get this working properly.

adw0rd commented 1 year ago

read this first https://adw0rd.github.io/instagrapi/usage-guide/interactions.html