Auto-disable iPhone API after 403 to avoid per-post retry penalty

Author: BitWise-0xCreated Feb 20, 2026Updated Sep 28, 2026
Labelsfeature suggestion

Problem

When the iPhone API (i.instagram.com) returns a 403 response (typically login_required), get_iphone_json() delegates to get_json() which retries max_connection_attempts times before raising ConnectionException. Since nothing records that the iPhone API is inaccessible for this session, this retry cycle repeats on every post.

For a profile with N images, this means N × max_connection_attempts failed requests with rate-limit sleeps between each — a significant and silent performance penalty for both CLI and library users.

Current behavior

Post 1: get_iphone_json → 403 → retry → 403 → retry → 403 → ConnectionException → fallback to CDN
Post 2: get_iphone_json → 403 → retry → 403 → retry → 403 → ConnectionException → fallback to CDN
Post 3: get_iphone_json → 403 → retry → 403 → retry → 403 → ConnectionException → fallback to CDN
...
Post N: (same pattern)

With max_connection_attempts=3 and a 200-post profile, this produces ~600 failed requests with sleep delays, causing downloads to appear to hang.

Expected behavior

Post 1: get_iphone_json → 403 → disable iphone_support → ConnectionException → fallback to CDN
Post 2: iphone_support=False → skip iPhone API → use CDN directly
Post 3: (same, no retries)
...
Post N: (same)

Existing workaround

The --no-iphone CLI flag exists for manual opt-out, but users may not know they need it until they notice downloads hanging. This proposal adds automatic detection to complement the existing manual flag.

Proposed fix

In get_iphone_json(), catch the ConnectionException after retries exhaust, and if it contains a 403 response, set self.iphone_support = False and log a message. All callers in structures.py already check context.iphone_support before attempting iPhone API calls (e.g., Post.url at line 430), so subsequent posts will skip the iPhone API entirely and fall back to CDN URLs.

This is a 4-line change with zero impact on users who don't encounter 403s. I have a PR ready with the implementation.