How to fix "instagrapi" python library error?

281 Views Asked by At

I get outputted a "KeyError" and I don't what's provoking it

My code: "

from instagrapi import Client

with open("credentials.txt", "r") as f:
    username, password = f.read().splitlines()

client = Client()
client.login(username, password)

hashtag = "bmw"

medias = client.hashtag_medias_recent(hashtag, 20)

for i, media in enumerate(medias):
    client.media_like(media.id)
    print(f"Liked post number {i+1} of hashtag {hashtag}")

"

Output :"

  File "C:\Users\Asus\Desktop\InstagramAutomation\InstagramBot.py", line 11, in <module>
    medias = client.hashtag_medias_recent(hashtag, 20)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Asus\AppData\Roaming\Python\Python311\site-packages\instagrapi\mixins\hashtag.py", line 444, in hashtag_medias_recent
    medias = self.hashtag_medias_recent_a1(name, amount)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Asus\AppData\Roaming\Python\Python311\site-packages\instagrapi\mixins\hashtag.py", line 407, in hashtag_medias_recent_a1
    return self.hashtag_medias_a1(name, amount, tab_key="recent")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Asus\AppData\Roaming\Python\Python311\site-packages\instagrapi\mixins\hashtag.py", line 222, in hashtag_medias_a1
    medias, _ = self.hashtag_medias_a1_chunk(name, amount, tab_key)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Asus\AppData\Roaming\Python\Python311\site-packages\instagrapi\mixins\hashtag.py", line 179, in hashtag_medias_a1_chunk
    result = data["data"][tab_key]
             ~~~~^^^^^^^^
KeyError: 'data'

"

I tried making an "InstagramBot", I was excepting to work and it didn't...

0

There are 0 best solutions below