Post.location raises KeyError: 'id' when Instagram returns a location without an id, aborting the download
Describe the bug
Since recently, Instagram sometimes returns a post's location dict without an id field. The Post.location property assumes the field is always present (structures.py, line 933 in v4.15.3):
location_id = int(loc['id'])so accessing it raises an uncaught KeyError: 'id', which aborts the whole download run (with --geotags, the crash happens inside Instaloader.download_post).
To Reproduce
instaloader --login=USER --geotags PROFILEwhere PROFILE contains a post whose location payload lacks id. I hit it on a reels video of a public profile while downloading with --geotags --reels --latest-stamps. The affected post's metadata contains a location object with some fields, but no id (and no pk).
Expected behavior
A missing location id should be treated like a post without a (usable) location — return None / skip the geotag — instead of crashing the entire multi-post download.
Error messages and tracebacks
Traceback (most recent call last):
File "instaloader\__main__.py", line 581, in main
File "instaloader\__main__.py", line 299, in _main
File "instaloader\instaloader.py", line 1522, in download_profiles
File "instaloader\instaloader.py", line 1300, in download_reels
File "instaloader\instaloader.py", line 1077, in posts_download_loop
File "instaloader\instaloader.py", line 782, in download_post
File "instaloader\structures.py", line 933, in location
KeyError: 'id'Instaloader version
4.15.3 (running from source at the v4.15.3 tag; PR #2730 applied on top for the HTTP/2 transport — the location code path itself is untouched by that PR, though I cannot rule out that the HTTP/2 rollout serves slightly different payloads).
Additional context
The following minimal change fixes it for me:
location_id_value = loc.get('id') or loc.get('pk')
if location_id_value is None:
return None
location_id = int(location_id_value)Happy to submit this as a PR if you want it.
Source: instaloader/instaloader