From 57d2ce95381cd713745b1557973ab61f63d03e4f Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Fri, 10 Apr 2020 11:57:36 +0200 Subject: [PATCH] Alleviate #449 by catching bad metadata response Instead of ungracefully failing with a TypeError, the Post is now skipped with an error message containing the invalid JSON. --- instaloader/structures.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/instaloader/structures.py b/instaloader/structures.py index 3b5ecd1..29a5b2e 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -134,6 +134,12 @@ class Post: pic_json = self._context.get_json("p/{0}/".format(self.shortcode), params={}) self._full_metadata_dict = pic_json['entry_data']['PostPage'][0]['graphql']['shortcode_media'] self._rhx_gis_str = pic_json.get('rhx_gis') + if self._full_metadata_dict is None: + # issue #449 + self._context.error("Fetching Post metadata failed (issue #449). " + "The following data has been returned:\n" + + json.dumps(pic_json['entry_data'], indent=2)) + raise BadResponseException("Fetching Post metadata failed.") if self.shortcode != self._full_metadata_dict['shortcode']: self._node.update(self._full_metadata_dict) raise PostChangedException