Skip to content

fix: bump psxdata to 1.1.1 to send PSX X-Req-Id token - #3

Merged
mtauha merged 1 commit into
mainfrom
chore/bump-psxdata-1.1.1
Sep 26, 2026
Merged

mtauha merged 1 commit into
mainfrom
chore/bump-psxdata-1.1.1

Conversation

@mtauha

@mtauha mtauha commented Sep 26, 2026

Copy link
Copy Markdown
Member

Summary

Since 2026-09-24, PSX has required an X-Req-Id request token on its data endpoints. The pinned psxdata==1.1.0 has no way to obtain or send that token, so BaseScraper._request gets a 403 and raises PSXAuthError on every call — meaning every data endpoint on the hosted API (/stocks, /indices, /sectors, /sectors/{name}/stocks, /screener) has been returning 502 upstream_data_error since then.

psxdata 1.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 as X-Req-Id on every request, refreshing and retrying once on a 403. It's a patch release with no public API changes — BaseScraper only gained an optional token_provider kwarg; PSXClient, the module-level functions, and the exception types are unchanged, so nothing else in this repo needs to change.

Changes:

  • pyproject.toml: psxdata pin 1.1.0 → 1.1.1; package version 0.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

  • Bug fix
  • New feature
  • Refactor (no behavior change)
  • Documentation
  • Infrastructure / CI

Testing Done

  • Installed psxdata==1.1.1 into an isolated venv in this worktree and confirmed psxdata.__version__ == "1.1.1".
  • ruff check api/ passes.
  • mypy api/ passes.
  • pytest tests/api/ -v — 60 passed (fully mocked, no live calls).
  • Manual live smoke test: started uvicorn api.main:app locally against real PSX and got 200 from /health, /stocks/HBL/quote, /sectors, /indices (previously 403-driven 502s).

Checklist

  • ruff check api/ passes
  • mypy api/ passes
  • CHANGELOG.md updated
  • pyproject.toml and api/requirements.txt pins kept in sync

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.
@mtauha
mtauha merged commit 963cb1a into main Sep 26, 2026
4 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.

1 participant