From db2ae98928a25cced21e0207ddbd19e7e725828a Mon Sep 17 00:00:00 2001 From: Mike Holzinger Date: Sun, 5 Jul 2026 15:04:29 -0400 Subject: [PATCH] Guard against null data in Post._obtain_metadata (#2705) When Instagram returns {"data": null} for a shortcode metadata query (e.g. under rate limiting, or for an unavailable post), response["data"]["xdt_shortcode_media"] raised a raw TypeError before the existing `if pic_json is None` check could run. Guard the intermediate "data" so the clean BadResponseException is raised instead, which the download loop already handles. --- instaloader/structures.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/instaloader/structures.py b/instaloader/structures.py index 30ccd37..c1f95c4 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -319,9 +319,11 @@ class Post: def _obtain_metadata(self): if not self._full_metadata_dict: - pic_json = self._context.doc_id_graphql_query( + response = self._context.doc_id_graphql_query( "8845758582119845", {"shortcode": self.shortcode} - )["data"]["xdt_shortcode_media"] + ) + data = (response or {}).get("data") + pic_json = data.get("xdt_shortcode_media") if data else None if pic_json is None: raise BadResponseException("Fetching Post metadata failed.") try: