Skip to content

fix: send an Apinator User-Agent so Cloudflare doesn't block requests - #5

Merged
toocool merged 1 commit into
mainfrom
fix/user-agent
Oct 25, 2026
Merged

toocool merged 1 commit into
mainfrom
fix/user-agent

Conversation

@toocool

@toocool toocool commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Why

Every request this SDK makes to production is blocked. Cloudflare in front of ws-{cluster}.apinator.io rejects urllib's default Python-urllib/3.x User-Agent with error 1010 (HTTP 403) before the request reaches the API. Users would see AuthenticationError: API request failed: Forbidden and blame their keys.

Same request, only the User-Agent differs:

User-Agent Response
Python-urllib/3.12 403, error code: 1010 (Cloudflare)
apinator-server-python/1.0.0 (Python 3.12) 400, invalid app_id (our API)
Go-http-client/1.1, node, undici, GuzzleHttp/7, PHP, empty 400 from our API, so the other server SDKs are unaffected

Nobody hit this yet because apinator-server was never on PyPI.

What changes

  • _request sends User-Agent: apinator-server-python/{__version__} (Python x.y.z).
  • test_trigger_single_channel asserts the header.

Verification

  • Tests pass on 3.9 and 3.12.
  • I built a wheel, installed it in a fresh venv and ran the console's publish snippet. Against a local stub that checks the HMAC independently, path, key, body and signature are correct. Against ws-eu.apinator.io with made-up credentials, the call now gets our API's invalid app_id instead of Cloudflare's 1010.

This should merge before the first PyPI release (#4, then the 1.1.0 release PR) so the first published version works.

Cloudflare in front of ws-{cluster}.apinator.io rejects urllib's default
"Python-urllib/x.y" User-Agent with error 1010 (403), before the request
reaches the API. Every call the SDK made against production failed with
AuthenticationError: API request failed: Forbidden.

Requests now carry "apinator-server-python/{version} (Python x.y.z)".
@toocool
toocool merged commit e1fe956 into main Oct 25, 2026
3 checks passed
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