Scraper API: send waitFor as an object, read the target status from http_code - #7
Merged
Merged
Conversation
…ttp_code Two defects in scraper_api_client.py, both measured 2026-09-23 against https://scraper.2captcha.com/tasks/sync: - waitFor was sent as a JSON-encoded string. The API answers that with HTTP 422 "params.waitFor must be an object" and still bills $0.0005; the object form answers HTTP 200. Every --wait-* run was a paid exit 5. - The target status was read from `status`, which is the API's own verdict string ("success"); the target's code is `http_code`. A target 403/503 therefore never reached detect_page_state. `status` is now a fallback only when it is an int. Adds test_scraper_api_waitfor_is_an_object to smoke_test.py (real parse_args/fetch_html, requests.post captured, no network). Control: with the old client restored the suite goes red on exactly those two checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two defects in the Scraper API client
Measured 2026-09-23 against
https://scraper.2captcha.com/tasks/sync.waitForwas sent as a JSON-encoded string._build_wait_forreturnedjson.dumps({...}), following a docstring that said the API wanted a double-encoded string. The live API refuses that with HTTP 422ScrapeParser: params.waitFor must be an object— and still bills the call ($0.0005). The same request with an object answers HTTP 200. So every--wait-text/--wait-element/--wait-staterun was a paid exit 5._build_wait_fornow returns a dict (Optional[dict]), logged throughjson.dumps, and the docstring says what was measured.status. The response is{"status": "success", "http_code": <int>, "headers": …, "body": …}:statusis the API's own verdict string,http_codeis the target site's HTTP code. The client passed"success"intodetect_page_state, so a target 403/503 was never seen (a live rakuten run loggedUpstream page status success). It now readshttp_code, falling back tostatusonly if that is an int.Regression check
test_scraper_api_waitfor_is_an_objectinsmoke_test.py: drives the realparse_args()+fetch_html()with--wait-text,requests.postmonkeypatched to capture the payload and return{"status":"success","http_code":403,"body":"<html></html>"}. AssertswaitForis a dict and the status handed onward is the int 403.Control: with
scraper_api_client.pyrestored fromorigin/main(edit asserted to change the file) the suite went red on exactly those two checks and nothing else; with the fix it is green.Live result
One call with the fixed client, key from the environment:
→ API HTTP 200 (no 422),
Upstream page status 200 (target HTTP code, from http_code), 508,559 bytes, real results-page title — 0 cards, exit 4. That is the shell this module's docstring already warns about: the text "Orlando" is in the page chrome, so the wait resolved before anylodging-cardpainted. The docstring's own recipe is--wait-element '[data-stid="lodging-card-responsive"]', which I did not spend a second paid call on. The point of this call was the 422, which is gone.Note: the docstring records a 2026-09-14 run that got HTTP 200 while the client was still sending the string form — so the API appears to have tightened its validation between then and 2026-09-23.
Not changed
[Unreleased].detect_page_stateare untouched — they already take an int status; they were just never given one.## [Unreleased]heading directly above[0.1.0]; removed it so the new### Fixedsits in the one Unreleased section. No released section touched.🤖 Generated with Claude Code