我输出了“KeyError”,但我不知道是什么引发了它
我的代码:“
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}")
”
输出:“
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'
”
我尝试制作一个“InstagramBot”,我正在工作,但它没有......
Eu alterei
if not result["more_available"]:
para if not result.get("more_available"):
没有 arquivo 'hashtag.py'(linha 195)。
Parou de dar o erro,porém não retornou nenhum post。