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.
This commit is contained in:
Mike Holzinger
2026-07-05 21:04:29 +02:00
committed by GitHub
parent b79a0a1e8b
commit db2ae98928
+4 -2
View File
@@ -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: