Skip to content

feat(proxy): add proxy support to AmazonCreatorsApi#150

Draft
mekarpeles wants to merge 1 commit into
sergioteula:masterfrom
mekarpeles:proxy-support
Draft

feat(proxy): add proxy support to AmazonCreatorsApi#150
mekarpeles wants to merge 1 commit into
sergioteula:masterfrom
mekarpeles:proxy-support

Conversation

@mekarpeles

@mekarpeles mekarpeles commented Jun 11, 2026

Copy link
Copy Markdown

Summary

Fixes two independent gaps that prevented AmazonCreatorsApi from routing traffic through an HTTP proxy. Closes #149.

Problem 1 — no proxy parameter: AmazonCreatorsApi.__init__ created ApiClient without a Configuration, so configuration.proxy was always None. RESTClientObject already handled urllib3.ProxyManager when configuration.proxy was set — it just wasn't reachable from the public API.

Problem 2 — token refresh bypassed proxy: OAuth2TokenManager.refresh_token() called requests.post() directly. Even with proxy config wired, token refresh on cold cache (worker restart, token expiry) still went direct.

Changes

  • amazon_creatorsapi/api.py — adds proxy: str | None = None to AmazonCreatorsApi.__init__; builds a Configuration with it and passes to ApiClient
  • creatorsapi_python_sdk/api_client.py — extracts configuration.proxy when lazily initialising _token_manager and passes it as a proxies dict
  • creatorsapi_python_sdk/auth/oauth2_token_manager.py — accepts proxies in __init__; refresh_token() uses requests.Session with .proxies set. Applies to both LWA (v3.x) and Cognito (v2.x) flows

Usage

from amazon_creatorsapi import AmazonCreatorsApi

api = AmazonCreatorsApi(
    credential_id="...",
    credential_secret="...",
    version="2.2",
    tag="your-tag",
    country="US",
    proxy="http://user:pass@proxy:3128",
)

Tests

  • tests/amazon_creatorsapi/api_test.py — 2 new tests verifying configuration.proxy is set (or None) on ApiClient based on the proxy param
  • tests/amazon_creatorsapi/oauth2_token_manager_test.py — new file, 3 tests: proxy applied on Cognito refresh, proxy applied on LWA refresh, no proxy → session not configured

39 tests passing, no regressions.

Known limitations

proxy_headers (for cases where credentials cannot be embedded in the URL) is not yet exposed. The current interface covers the common case of credential-bearing proxy URLs.

Real-world context

This unblocks Internet Archive / Open Library, which runs behind an authenticated Squid proxy and currently carries two workarounds:


This PR was developed with Claude (claude-sonnet-4-6) as co-author.

Fixes two independent gaps that prevented routing traffic through an
HTTP proxy:

1. AmazonCreatorsApi.__init__ now accepts a `proxy` URL parameter and
   passes it to ApiClient via a Configuration object. RESTClientObject
   already used urllib3.ProxyManager when configuration.proxy was set;
   this just wires the public API through to it.

2. OAuth2TokenManager.refresh_token() previously called requests.post()
   directly, bypassing any proxy configuration. It now creates a
   requests.Session and sets .proxies when a proxy URL is provided,
   ensuring token refresh on cold cache also routes through the proxy.

Closes sergioteula#149

Co-authored-by: Claude (claude-sonnet-4-6) <claude[bot]@users.noreply.github.com>
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.

AmazonCreatorsApi has no proxy support — regular calls and OAuth2 token refresh both bypass HTTP proxy

1 participant