fix(carousell_sg): add PROXY_PROVIDER switching and forward proxy env (BUY-63593) - #239
Draft
BuyWhere wants to merge 1 commit into
Draft
fix(carousell_sg): add PROXY_PROVIDER switching and forward proxy env (BUY-63593)#239BuyWhere wants to merge 1 commit into
BuyWhere wants to merge 1 commit into
Conversation
BUY-63593: Carousell SG daemon was producing 0 products with 407 Invalid
Auth because (a) the scraper had no path to fall back to ScraperAPI when
BrightData account `hl_3ab737be` is suspended, and (b) the scheduler
stripped the subprocess env down to {SCRAPERAPI_KEY, BUYWHERE_API_KEY},
dropping all BRIGHTDATA_* credentials so the scraper built proxy URLs
with empty passwords.
scrapers/carousell_sg.py:
- Add PROXY_PROVIDER env default ("brightdata") and --proxy-provider
CLI flag with {brightdata, scraperapi} choices.
- CarousellSGScraper accepts proxy_provider; __aenter__ skips the
httpx tunnel when provider is scraperapi (ScraperAPI is a request
router, not a tunnel).
- Split _fetch_page into _fetch_page_brightdata (3 retries, current
behavior) and _fetch_page_scraperapi (single attempt that surfaces
the upstream 401/403 body immediately so exhausted credits aren't
masked by retry delays).
- Summary records proxy_provider; __aenter__ logs it on startup.
scripts/scraper_scheduler.py:
- Add --proxy-provider CLI flag forwarded to the subprocess.
- New _build_proxy_env() forwards SCRAPERAPI_KEY, BUYWHERE_API_KEY,
PROXY_PROVIDER, BRIGHTDATA_RESIDENTIAL_*, BRIGHTDATA_DATACENTER_*,
and BRIGHTDATA_* legacy vars from the scheduler process so the
scraper can authenticate regardless of provider.
- Continuous and single-run paths use _build_proxy_env(); only require
SCRAPERAPI_KEY when provider == scraperapi.
Verified: import + dry-run fetch for both providers surfaces the
expected auth failure cleanly (ScraperAPI 401, BrightData 407) without
crashes. Full recovery still blocked on BUY-56686 (BrightData zone
reactivation, human-action-router) and ScraperAPI credit top-up.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
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.
What
Adds a
--proxy-provider {brightdata,scraperapi}flag to the Carousell SG scraper and routes the scheduler subprocess env to forward the relevant proxy credentials. Closes the actionable code half of BUY-63593.Why
The Carousell SG daemon was producing 0 products with
407 Invalid Auth. Two root causes in this workspace:scrapers/carousell_sg.pyhad no path to use ScraperAPI, so when the BrightData customerhl_3ab737beis suspended, the scraper has no other option.scripts/scraper_scheduler.pycreated a freshenvdict with only{SCRAPERAPI_KEY, BUYWHERE_API_KEY}for the subprocess. AllBRIGHTDATA_*credentials were dropped, soproxy_config.proxy_url(Zone.RESIDENTIAL_PROXY1)built proxy URLs with empty passwords, causing 407 even when the upstream zone was healthy.The BrightData suspension is still owned by BUY-56686 (human-action-router, Rich). ScraperAPI credits are still at 0. With this fix, switching to ScraperAPI is a one-flag flip once credits are topped up, and the BrightData path will also work as soon as the zone is reactivated.
Changes
scrapers/carousell_sg.pyPROXY_PROVIDERenv default (brightdata) and--proxy-providerCLI arg with{brightdata, scraperapi}choices.CarousellSGScraper.__init__acceptsproxy_provider;__aenter__skips the httpx tunnel proxy when provider isscraperapi._fetch_pageinto_fetch_page_brightdata(3 retries, current behavior) and_fetch_page_scraperapi(single attempt that surfaces the upstream 401/403 body immediately so exhausted credits are not masked by retry delays).run()summary recordsproxy_provider;__aenter__logs it on startup.scripts/scraper_scheduler.py--proxy-providerCLI flag forwarded to the subprocess._build_proxy_env()forwardsSCRAPERAPI_KEY,BUYWHERE_API_KEY,PROXY_PROVIDER,BRIGHTDATA_RESIDENTIAL_*,BRIGHTDATA_DATACENTER_*, and the legacyBRIGHTDATA_*vars from the scheduler process._build_proxy_env(). Only requireSCRAPERAPI_KEYwhen provider isscraperapi.Verification
proxy provider: <name>is logged at__aenter__.https://www.carousell.sg/categories/electronics-phones/:brightdata: 3x407 Auth failedthenNone(matches current behavior; expected until zone reactivated).scraperapiwith dummy key:401 Unauthorized request, please make sure your API key is valid.in a single attempt.Operational notes
serviceInstanceDeployV2(commitSha="161ad33d8")onfix/BUY-63593-carousell-proxy-provider(not main).data/carousell-sg/products_*.jsonlwith nonzero rows will only appear once the upstream proxy accounts are healthy: BUY-56686 (BrightData reactivation) and/or ScraperAPI credit top-up.Co-Authored-By: Paperclip noreply@paperclip.ing