Skip to content

Fix CDN downloads: Use requests with proxy support#2379

Closed
obervinov wants to merge 6 commits intosubzeroid:masterfrom
obervinov:fix/cdn-downloads
Closed

Fix CDN downloads: Use requests with proxy support#2379
obervinov wants to merge 6 commits intosubzeroid:masterfrom
obervinov:fix/cdn-downloads

Conversation

@obervinov
Copy link

@obervinov obervinov commented Feb 18, 2026

v2.2.2 - 2026-02-18

What's Changed

CDN Download Fix: Direct CDN requests with proxy support for media downloads

🐛 Bug Fixes

  • Fixed 404 errors on media downloads through proxy: CDN URLs now use direct requests but still route through proxy

- Make scans_profile optional in SharedMediaImageCandidate (handles missing field in image_versions2)
- Add defensive check for missing pinned_channels_info in extract_broadcast_channel
- Fixes issues subzeroid#2254 and subzeroid#2257 where API responses don't include expected fields
**Security improvements:**
- Reverse media_info() priority: Try private API first, fall back to public GraphQL
- Replace direct requests.get() with self.private.get() to route through proxy
- Disable suspicious public GraphQL calls that trigger Instagram detection

**Files changed:**
- instagrapi/mixins/media.py: Reverse media_info() logic (private-first)
- instagrapi/mixins/video.py: Use media_info_v1() and self.private.get()
- instagrapi/mixins/photo.py: Use media_info_v1() and self.private.get()
- instagrapi/mixins/album.py: Use media_info_v1() for all downloads
- instagrapi/mixins/track.py: Use self.private.get() for audio downloads

**Benefits:**
- All network traffic routes through configured SOCKS proxy
- Eliminates web-based User-Agent mixing (Safari vs Android)
- Uses authenticated mobile API endpoints exclusively
- Prevents 401 'Please wait few minutes' errors
- Removed old python-package.yml and codeql-analysis.yml
- Added pr.yaml for validation (checks CHANGELOG version/date)
- Added release.yaml for automated tag/release creation
- Uses existing _templates@v2.1.1 workflows (same as users-package)
- Cleaner, maintainable, centralized CI configuration
…icated session

CDN URLs are now downloaded with direct requests but still route through
configured proxy to preserve Instagram CDN Host headers. This fixes 404 errors.

- Changed video_download_by_url() to use requests.get() with proxies parameter
- Changed video_download_by_url_origin() to use requests.get() with proxies
- Changed photo_download_by_url() to use requests.get() with proxies
- Changed photo_download_by_url_origin() to use requests.get() with proxies
- Changed track_download_by_url() to use requests.get() with proxies
- All CDN downloads now use 'proxies=self.private.proxies' to route through proxy

SECURITY: CDN downloads still use proxy routing for privacy, but direct HTTP
calls to avoid Host header issues. Private API queries continue to use
self.private.get() with full authentication.

Version v2.2.2
Copilot AI review requested due to automatic review settings February 18, 2026 12:42
@obervinov obervinov closed this Feb 18, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements fixes for CDN media downloads by reverting from authenticated session requests to direct HTTP requests with proxy support. The PR addresses 404 errors that occurred when using authenticated sessions for CDN downloads (v2.2.1) while still maintaining proxy routing.

Changes:

  • Modified download methods (video, photo, track) to use requests.get() with proxies=self.private.proxies instead of authenticated session calls
  • Changed media_info() to prioritize private API (v1) over public GraphQL, with fallback logic
  • Made scans_profile field optional in SharedMediaImageCandidate type to fix Pydantic validation errors
  • Added defensive checks for pinned_channels_info in broadcast channel extraction
  • Replaced upstream workflows with reusable workflows from obervinov/_templates
  • Updated download methods (photo_download, video_download, album_download) to use media_info_v1 directly

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
instagrapi/types.py Made scans_profile optional to handle missing field in API responses
instagrapi/mixins/video.py Added proxy support to CDN downloads and switched to media_info_v1
instagrapi/mixins/track.py Added proxy parameter to track downloads from CDN
instagrapi/mixins/photo.py Added proxy support to photo CDN downloads and switched to media_info_v1
instagrapi/mixins/media.py Reversed API priority to try private API first, public GraphQL as fallback
instagrapi/mixins/album.py Changed to use media_info_v1 directly for album downloads
instagrapi/extractors.py Added defensive null checks for pinned_channels_info field
FORK_README.md Added comprehensive documentation for fork features and fixes
CHANGELOG.md Added version history with v2.2.2 and v2.2.1 changes
.github/workflows/release.yaml New workflow using reusable template from obervinov/_templates
.github/workflows/pr.yaml New PR validation workflow using reusable template
.github/workflows/python-package.yml Removed original upstream workflow
.github/workflows/codeql-analysis.yml Removed original upstream workflow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +55 to +58
2. **Security & Proxy implementation** (841e9d1)
- Reverse API priority (private first)
- Replace `requests.get()` with `self.private.get()`
- Use private API in all download methods
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FORK_README states that the changes "Replace requests.get() with self.private.get()" but the actual code in this PR uses requests.get() with the proxies=self.private.proxies parameter. The CHANGELOG v2.2.2 clarifies that this PR is fixing 404 errors that occurred when using self.private.get() for CDN downloads, reverting to direct requests with proxy support. Consider updating this section to accurately reflect the v2.2.2 changes or clarifying that this describes v2.2.1.

Copilot uses AI. Check for mistakes.
```toml
[tool.poetry.dependencies]
# Use the fork with fixes
instagrapi = { git = "https://github.com/obervinov/instagrapi.git", tag = "v2.2.1" }
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FORK_README references tag "v2.2.1" but this PR appears to be for version v2.2.2 according to the CHANGELOG. Consider updating this reference to "v2.2.2" or a more generic approach that doesn't hardcode the version.

Copilot uses AI. Check for mistakes.
@obervinov
Copy link
Author

Sorry, accidental PR. Wrong repo - changes are for my fork (https://github.com/obervinov/instagrapi).
Closing it now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants