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] login_required when trying to call hashtag_medias_top after sucsessful login #618

Closed iZucked closed 1 year ago

iZucked commented 2 years ago

Describe the bug

Sometimes it will allow me to access the top media posts but after that media_likers will return a login_required exception

To Reproduce

Example of cookies dictionary passed in to Client settings:

Traceback `Traceback (most recent call last): File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/public.py", line 128, in _send_public_request response.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://www.instagram.com/explore/locations/39602068/?__a=1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/location.py", line 171, in location_info location = self.location_info_a1(location_pk) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/location.py", line 132, in location_info_a1 data = self.public_a1_request(f"/explore/locations/{location_pk}/") or {} File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/public.py", line 173, in public_a1_request response = self.public_request( File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/public.py", line 89, in public_request raise e File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/public.py", line 72, in public_request return self._send_public_request(url, **kwargs) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/public.py", line 161, in _send_public_request raise ClientError(e, response=e.response) instagrapi.exceptions.ClientError: 500 Server Error: Internal Server Error for url: https://www.instagram.com/explore/locations/39602068/?__a=1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/private.py", line 298, in _send_private_request response.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 943, 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/locations/39602068/location_info/

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/hashtag.py", line 360, in hashtag_medias_top medias = self.hashtag_medias_top_a1(name, amount) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/hashtag.py", line 323, in hashtag_medias_top_a1 return self.hashtag_medias_a1(name, amount, tab_key="edge_hashtag_to_top_posts") File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/hashtag.py", line 220, in hashtag_mediasa1 medias, = self.hashtag_medias_a1_chunk(name, amount, tab_key) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/hashtag.py", line 184, in hashtag_medias_a1_chunk medias.append(self.media_info_gql(media_pk)) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/media.py", line 209, in media_info_gql data["shortcode_media"]["location"] = self.location_complete( File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/location.py", line 68, in location_complete info = self.location_info(location.pk) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/location.py", line 177, in location_info location = self.location_info_v1(location_pk) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/location.py", line 153, in location_info_v1 result = self.private_request(f"locations/{location_pk}/location_info/") File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/private.py", line 445, in private_request raise e File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/private.py", line 432, in private_request self._send_private_request(endpoint, kwargs) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/private.py", line 323, in _send_private_request raise LoginRequired(response=e.response, last_json) instagrapi.exceptions.LoginRequired: login_required

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/private.py", line 298, in _send_private_request response.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 943, 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/tags/nft/sections/

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/application.py", line 356, in get_top_posts posts = self._bot.get_top_hashtag_posts(hashtag, num_posts) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/Bot.py", line 118, in get_top_hashtag_posts return self._cl.hashtag_medias_top(hashtag, num_posts) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/hashtag.py", line 362, in hashtag_medias_top medias = self.hashtag_medias_top_v1(name, amount) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/hashtag.py", line 341, in hashtag_medias_top_v1 return self.hashtag_medias_v1(name, amount, tab_key="top") File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/hashtag.py", line 302, in hashtag_mediasv1 medias, = self.hashtag_medias_v1_chunk(name, amount, tab_key) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/hashtag.py", line 259, in hashtag_medias_v1_chunk result = self.private_request( File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/private.py", line 445, in private_request raise e File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/private.py", line 432, in private_request self._send_private_request(endpoint, kwargs) File "/home/izucked/Desktop/Instagram-Mass-DM-Bot/instagrapi/mixins/private.py", line 323, in _send_private_request raise LoginRequired(response=e.response, last_json) instagrapi.exceptions.LoginRequired: login_required`

Expected behavior

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

lolo9538 commented 2 years ago

I'm having the same issue....