Repository navigation
fix: bump psxdata to 1.1.1 to send PSX X-Req-Id token - #3
Merged
Merged
Conversation
PSX started requiring an X-Req-Id request token on its data endpoints on 2026-09-24, so every psxdata call raises PSXAuthError on a 403 and every data endpoint here has been returning 502 upstream_data_error since then. psxdata 1.1.1 fetches and sends the token automatically (psxdata/psxdata#161, fixed in psxdata/psxdata#163). No API changes on our side: BaseScraper only gained an optional token_provider kwarg, PSXClient/module functions/exceptions are unchanged. Bumped the pin in both pyproject.toml and api/requirements.txt to keep them in sync, per established convention, and bumped this package to 0.2.1 for the fix. Verified against the published 1.1.1 wheel: ruff/mypy/pytest all pass, and a local uvicorn smoke test against live PSX returns 200s from /health, /stocks/HBL/quote, /sectors and /indices instead of the 403- driven errors.
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.
Summary
Since 2026-09-24, PSX has required an
X-Req-Idrequest token on its data endpoints. The pinnedpsxdata==1.1.0has no way to obtain or send that token, soBaseScraper._requestgets a 403 and raisesPSXAuthErroron every call — meaning every data endpoint on the hosted API (/stocks,/indices,/sectors,/sectors/{name}/stocks,/screener) has been returning502 upstream_data_errorsince then.psxdata1.1.1 fixes this at the source: a process-wide token provider reads the token from the PSX home page, caches it briefly, and sends it asX-Req-Idon every request, refreshing and retrying once on a 403. It's a patch release with no public API changes —BaseScraperonly gained an optionaltoken_providerkwarg;PSXClient, the module-level functions, and the exception types are unchanged, so nothing else in this repo needs to change.Changes:
pyproject.toml:psxdatapin1.1.0→1.1.1; package version0.2.0→0.2.1.api/requirements.txt: same pin bump, kept in sync per the convention established for the Dockerfile/FastAPI Cloud fallback dependency source.CHANGELOG.md: new[0.2.1]entry.Related Issue
Root cause tracked and fixed upstream in psxdata/psxdata#161 / psxdata/psxdata#163. No open issue in this repo to link — the outage is entirely explained by the upstream pin.
Type of Change
Testing Done
psxdata==1.1.1into an isolated venv in this worktree and confirmedpsxdata.__version__ == "1.1.1".ruff check api/passes.mypy api/passes.pytest tests/api/ -v— 60 passed (fully mocked, no live calls).uvicorn api.main:applocally against real PSX and got200from/health,/stocks/HBL/quote,/sectors,/indices(previously 403-driven502s).Checklist
ruff check api/passesmypy api/passesCHANGELOG.mdupdatedpyproject.tomlandapi/requirements.txtpins kept in sync