Skip to content

_parse_retry_after compares a string to an int #17100

Description

@Fyko

Component

CLI

Priority

P0 - Critical (Blocking work)

SDK Language(s)

Python

Bug Description

The blind except masks a bug trying to compare a string to and int, and has never worked.

Example:

def _parse_retry_after(response_headers: httpx.Headers) -> typing.Optional[float]:
"""
This function parses the `Retry-After` header in a HTTP response and returns the number of seconds to wait.
Inspired by the urllib3 retry implementation.
"""
retry_after_ms = response_headers.get("retry-after-ms")
if retry_after_ms is not None:
try:
return int(retry_after_ms) / 1000 if retry_after_ms > 0 else 0
except Exception:
pass

Versions

0.19.0-rc5 to latest

Workaround

No

Are you interested in contributing a fix?

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions