Update scrapingbee-cli package to support Header based Authorization - #32
Conversation
…SCR-585)
- All Client requests now authenticate via 'Authorization: Bearer' instead
of the deprecated api_key query parameter, so the key no longer appears
in request URLs. Applies to every command including auth validation and
usage; crawl's scrapy-scrapingbee middleware still builds api_key URLs
and migrates separately.
- google --nb-results: requested results per page. Absent from llms.txt
but verified live: the API strictly rejects unknown params (400 'Unknown
field' control) yet accepts nb_results with 200.
- amazon-product --autoselect-variant: matches the existing amazon-search
flag; same live verification (200 vs 400 bogus-param control).
- Skill docs: --custom-google price corrected 15 -> 20 credits per the
API's own error message ('Each request will cost 20 credits!').
Live-verified via pipx build: usage/GET/PUT all 200 under Bearer auth,
nb-results and autoselect-variant accepted. 863 unit tests green (new:
Bearer session header, no api_key in GET/POST/usage params, param
forwarding for both new options); ruff + ty clean.
Regression:
|
-X post with |
--forward-headers true → target sees |
--forward-headers-pure true → target sees |
|---|---|---|
-H "X-Custom: 1" |
(nothing) | (nothing) |
-H "Spb-X-Custom: 1" |
X-Custom: 1 |
X-Custom: 1 |
-H "Authorization: Basic …" |
(nothing) | (nothing) |
-H "Spb-Authorization: Basic …" |
Authorization: Basic … |
Authorization: Basic … |
So the raw branch at line 238 was silently dropping every header anyway; prefixing fixes the auth clash and makes -H on POST/PUT actually work. With the patch applied: the three tests above pass, the existing tests/unit/test_client.py suite passes (74), and the live command returns HTTP 200 with httpbin showing "Authorization": "Basic Zm9vOmJhcg==" (i.e. the header now reaches the target; on main it never did).
Related, same code path: the --forward-headers help says "Use -H with Spb- prefix for GET", but the CLI already prefixes on GET, so a user who follows that hint gets Spb-Spb-X-Custom and the target receives Spb-X-Custom: 1 (verified on main). With the fix above the hint can simply go — or make the prefixing idempotent (if not k.lower().startswith("spb-")).
kostas-jakeliunas-sb
left a comment
There was a problem hiding this comment.
See comment, would be nice to fix this, apart from that otherwise looks good i think :)
- Custom -H headers are now Spb--prefixed on every method (idempotently),
not only GET. On POST/PUT raw headers were silently dropped by the API,
and after the Bearer migration a user Authorization header replaced the
session's API key (aiohttp per-request beats session headers), failing
auth with 400/401. Red->green verified live with the reviewer's repro;
fake-API regression tests added (3 fail without the fix).
- Stale --forward-headers help ('use Spb- prefix') removed — following it
produced Spb-Spb- double prefixes; prefixing is now automatic.
- google --pages billing corrected in CHANGELOG and references: flat 10/15
per request regardless of page count (measured: --pages 1/2/2-from-2 all
cost 10). Window semantics (--page start, N consecutive) re-verified by
URL-overlap comparison and were already documented correctly.
- youtube-subtitles: a language with no subtitles returns HTTP 200 with an
empty object (not 404 as the API docs claim) and still charges 5 credits
(verified live) — the CLI now warns instead of printing silent empty
JSON; docs corrected; unit tests added.
- youtube-subtitles added to the error-response, integration, and e2e test
registries.
Switches API auth from the deprecated
api_keyquery param to theAuthorization: Bearerheader, so the key no longer shows up in URLs. The only exception iscrawl, whose scrapy-scrapingbee middleware will be migrated separately.Also adds two params that are missing from the docs but confirmed working against the live API (it rejects unknown params with 400, these return 200):
google --nb-resultsamazon-product --autoselect-variantStays on 1.6.0 since it isn't published yet; release date set to 2026-08-24.
Tested live on a pipx install (usage, GET, PUT, both new flags) plus unit tests for the new behavior. Based on #31 — merge that first, with a merge commit (not squash).