Log in again automatically when the session expires - #164
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #164 +/- ##
==========================================
+ Coverage 97.55% 98.16% +0.61%
==========================================
Files 7 7
Lines 1185 1255 +70
Branches 130 133 +3
==========================================
+ Hits 1156 1232 +76
+ Misses 18 13 -5
+ Partials 11 10 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
RazerM
force-pushed
the
feature/reauth
branch
6 times, most recently
from
August 22, 2026 23:02
1a54261 to
09a4051
Compare
Space-Track sessions last two hours and are refreshed by activity (verified against the live API: each request returns a rotated session cookie with a renewed Max-Age, and after 2.5 idle hours queries return HTTP 401 with a JSON error body). A long-idle client previously failed every subsequent request, because nothing ever cleared _authenticated and so the client never logged in again. On a 401, read the response, re-authenticate, and retry the request once; a second 401 raises as before. 401 is the only trigger: 403 is not treated as session expiry since it plausibly means missing account permissions, where re-authenticating would only add login spam. The Cookie header is set when a request is built, so the retry replaces it from the cookie jar, which only sets the header on requests that have none. An upload is only retried if its body can be sent again: bytes, str, or a seekable file object, which HTTPX rewinds. A non-seekable stream would otherwise be sent empty the second time.
The upload branch of _generic_request_generator was not covered.
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.
A session that expired after two hours without requests caused every subsequent request to fail, since the client never logged in again. A 401 response now triggers a fresh login and a single retry of the request.
Confirmed against the live API: sessions are extended by activity, and an idle session returns a 401 with a JSON error body.