From 5c5c633beeb85d385ef3eddb32d61555902e1946 Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Fri, 10 Apr 2020 14:39:40 +0200 Subject: [PATCH] Catch Exceptions raised during filter evaluation Closes #192. --- instaloader/instaloader.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index 3215aaf..2ef96d6 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -701,6 +701,8 @@ class Instaloader: """ Download the Posts returned by given Post Iterator. + ..versionadded:: 4.4 + :param posts: Post Iterator to loop through. :param target: Target name :param fast_update: :option:`--fast-update` @@ -722,9 +724,14 @@ class Instaloader: end="", flush=True) else: self.context.log("[{:3d}] ".format(number + 1), end="", flush=True) - if post_filter is not None and not post_filter(post): - self.context.log("{} skipped".format(post)) - continue + if post_filter is not None: + try: + if not post_filter(post): + self.context.log("{} skipped".format(post)) + continue + except (InstaloaderException, KeyError, TypeError) as err: + self.context.error("{} skipped. Filter evaluation failed: {}".format(post, err)) + continue with self.context.error_catcher("Download {} of {}".format(post, target)): # The PostChangedException gets raised if the Post's id/shortcode changed while obtaining # additional metadata. This is most likely the case if a HTTP redirect takes place while