subzeroid / instagrapi

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

[BUG] story_seen method yields Media not found or unavailable and Invalid media_id 0 #796

Closed Jackhammer9 closed 2 years ago

Jackhammer9 commented 2 years ago

Describe the bug I was trying to automate watching stories from specific users, however it keeps throwing an exception "Invalid media_id 0" or "Media not found or avaliable" for any user. I tried using different accounts yet got no success.

To Reproduce

from instagrapi import Client

cl = Client()
cl.login("username","password")

stories = cl.user_stories(cl.user_id_from_username("khloekardashian"))
for story in stories:
    story_id = story.dict()['pk']
    print(story_id)
    try:
        cl.story_seen(story_id)
        print("seen")
    except Exception as e:
        print(e)

Traceback

Traceback (most recent call last):
  File "D:\python\test.py", line 10, in <module>
    cl.story_seen(story_id)
  File "D:\Python 3.10.2\lib\site-packages\instagrapi\mixins\story.py", line 237, in story_seen
    [self.media_id(mid) for mid in story_pks],
  File "D:\Python 3.10.2\lib\site-packages\instagrapi\mixins\story.py", line 237, in <listcomp>
    [self.media_id(mid) for mid in story_pks],
  File "D:\Python 3.10.2\lib\site-packages\instagrapi\mixins\media.py", line 56, in media_id
    user = self.media_user(media_id)
  File "D:\Python 3.10.2\lib\site-packages\instagrapi\mixins\media.py", line 371, in media_user
    return self.media_info(media_pk).user
  File "D:\Python 3.10.2\lib\site-packages\instagrapi\mixins\media.py", line 268, in media_info
    media = self.media_info_v1(media_pk)
  File "D:\Python 3.10.2\lib\site-packages\instagrapi\mixins\media.py", line 234, in media_info_v1
    raise MediaNotFound(e, media_pk=media_pk, **self.last_json)

Expected behavior All the stories from user ("khloekardashian") in this case should be marked as seen.

Desktop (please complete the following information):

adw0rd commented 2 years ago

story_pks should be a list! Read this https://adw0rd.github.io/instagrapi/usage-guide/story.html

and use story.pk instead of story.dict()['pk']

cl.story_seen([story.pk])
adw0rd commented 2 years ago

Added assertions for story_seen

instagrapi 1.16.26

https://github.com/adw0rd/instagrapi/commit/c99ce908ce9ff16ac52d7286c0f5c2bfc2d1c4ca