Skip to content

Read timeout errors are converted to connection errors by adapter #5517

@janheindejong

Description

@janheindejong

When adding an adapter with a retry object to a session, read timeout errors are converted to connection errors.

>>> s = requests.Session()
>>> s.get("http://whatever.com", timeout=(3.05, 0.001))
Timeout: HTTPConnectionPool(host='whatever.com', port=80): Read timed out. (read timeout=0.001)
>>> a = HTTPAdapter(max_retries=Retry(total=3))
>>> s.mount("http://", a) 
>>> s.get("http://whatever.com", timeout=(3.05, 0.001))
ConnectionError: HTTPConnectionPool(host='whatever.com', port=80): Max retries exceeded with url: / (Caused by ReadTimeoutError("HTTPConnectionPool(host='whatever.com', port=80): Read timed out. (read timeout=0.001)"))

Is this intentional? If so, what's the reasoning behind it? I'd like to catch these errors, but handle connection errors differently (e.g. warn the user to check his internet connection) from timeout errors (e.g. inform the user that the requested resource is possibly overloaded). Wouldn't it make more sense to raise the original error type once the max number of retries is exceeded?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions