Reputation: 31
I am making my first Instagram bot, but it's not working completely. It stops working just before liking the post.
This is the error.
Traceback (most recent call last):
File "C:\Users\Aniket\PycharmProjects\insta_bot1\main.py", line 9, in <module>
session.like_by_tags(['photography', 'lighting', 'nature'], amount = 3)
File "C:\Python3.9\lib\site-packages\instapy\instapy.py", line 1957, in like_by_tags
inappropriate, user_name, is_video, reason, scope = check_link(
File "C:\Python3.9\lib\site-packages\instapy\like_util.py", line 633, in check_link
media = post_page[0]["shortcode_media"]
KeyError: 0
Process finished with exit code 1
This is my code.
from instapy import InstaPy
session = InstaPy(username = 'insta_bot._1', password = '####')
session.login()
session.set_relationship_bounds(enabled = True, max_followers = 150)
session.set_do_follow(True, percentage = 100)
session.like_by_tags(['photography', 'lighting', 'nature'], amount = 3)
session.end()
Please help me in resolving the error.
Upvotes: 3
Views: 2938
Reputation: 41
This worked for me:
Edit the file "instapy/like_util.py" , from line: 619 with the code:
media = post_page['items'][0]
is_video = media["is_unified_video"]
user_name = media["user"]["username"]
image_text = media["caption"]["text"]
owner_comments = ""
Upvotes: 1
Reputation: 1
So i found the problem, its due to instagram cause they changing the source code. so go to like_util.py
file then line 619
then change the code by this:
media = post_page ['items'] [0]
is_video = media ["is_unified_video"]
user_name = media ["user"] ["username"]
image_text = media ["caption"] ["text"]
owner_comments = "",
user_nmame,
Upvotes: 0
Reputation: 182
I had the same error and it stems from Instagram changing place in website source where they store post information that your InstaPy bot looks for (I am an InstaPy newbie also, please don't judge me too harshly on the specificity of this answer).
It has been fixed in the issue linked by Michael and it has been merged to InstaPy master on GitHub, but it wasn't included in the newest release of the library that I downloaded using IDE.
The easiest thing you can do right now (short of waiting for a new release of the package, that will include those changes) is to download the master from here and substitute files on your computer (or wherever you create that bot) with those from instapy folder within repo you downloaded.
Here you can find more information about the fix.
Upvotes: 3