Instapyのエラー対処

instayp の 関数:like_by_tags でエラー対処を行ったためメモ

import configparser
import os
import platform

from InstaPy.instapy import InstaPy
from InstaPy.instapy import smart_run

class Unfollow:
    def __init__(self):

    def headless_flg(self):
        pf = platform.system()
        if pf == 'Windows':
            flg = False
        elif pf == 'Darwin':
            flg = False
        elif pf == 'Linux':
            flg = True
        return flg

    def unfollow(self):
        headless_flg = self.headless_flg()
        for user_name in user_names:
            # get an InstaPy session!
            # set headless_browser=True to run InstaPy in the background
            session = InstaPy(username='test',
                              password='test',
                              headless_browser=headless_flg,  # headless mode
                              page_delay=int(15))

            with smart_run(session):
                # activity
                session.like_by_tags(eval(config_ini[user_name]["TAGS"]), amount=15)

def main():
    unfollow = Unfollow()
    unfollow.unfollow()

if __name__ == '__main__':
   main()

以下のようなエラーを確認する。

python3 test.py

Traceback (most recent call last):
File "D:\Instabot\instagram_bot.py", line 58, in
session.like_by_feed(amount=65, randomize=False, unfollow=False, interact=True)
File "C:\Users\zunam\AppData\Roaming\Python\Python310\site-packages\instapy\instapy.py", line 4137, in like_by_feed
for _ in self.like_by_feed_generator(amount, randomize, unfollow, interact):
File "C:\Users\zunam\AppData\Roaming\Python\Python310\site-packages\instapy\instapy.py", line 4244, in like_by_feed_generator
) = check_link(
File "C:\Users\zunam\AppData\Roaming\Python\Python310\site-packages\instapy\like_util.py", line 619, in check_link
media = post_page[0]["shortcode_media"]
KeyError: 0

上記のエラーについて、次のissueが発行されている github.com

次のページにて、パッチを当てたソースが作成されている。なお、masterブランチには未反映である。 github.com

こちらのパッチを当てたソースを使うことでエラーを回避できた。

振り返りとしては、instagramのようなwebアプリは早いスパンで開発されており 変更が早く、その変更によりエラーが発生している。 エラー文で検索し、issue、またそのissueに対するパッチがgithubなどで議論されたり、作成されいないか、確認する。