Skip to content

fix: wrap urllib3 DecodeError and TimeoutError exceptions in requests API#102

Open
label-hook[bot] wants to merge 1784 commits into
mainfrom
phoenix/issue-101
Open

fix: wrap urllib3 DecodeError and TimeoutError exceptions in requests API#102
label-hook[bot] wants to merge 1784 commits into
mainfrom
phoenix/issue-101

Conversation

@label-hook

@label-hook label-hook Bot commented Apr 18, 2026

Copy link
Copy Markdown

Summary

This PR addresses issue #101 where urllib3 exceptions were leaking through the requests API instead of being wrapped in requests-specific exception classes. Users had to catch both requests exceptions and urllib3 exceptions, which breaks the abstraction layer that requests is meant to provide.

Changes

  • Added new exception classes in requests/exceptions.py:

    • DecodeError: Wraps urllib3.exceptions.DecodeError and inherits from RequestException
    • TimeoutError: Wraps urllib3.exceptions.TimeoutError and inherits from Timeout
  • Modified requests/adapters.py:

    • Added exception handling in the HTTP adapter to catch urllib3 DecodeError and TimeoutError
    • Re-raises them as the corresponding requests exception classes
    • Preserves original exception information while maintaining requests API consistency

These changes ensure that users only need to catch requests exceptions and don't have to deal with urllib3 implementation details leaking through the API.

Testing

The baseline test suite was already failing before these changes, and no new test failures were introduced. The implementation follows the existing pattern used for other urllib3 exception wrapping in the codebase, ensuring consistency with the current exception handling approach.

Closes #101


Closes #101

sigmavirus24 and others added 30 commits November 7, 2014 14:18
Cap the redirect_cache size to prevent memory abuse
Ensure pos is set to None when the body is not a file
so that HTTPDigestAuth detects the type of the body correctly.
Fix HTTPDigestAuth not to treat non-file as a file
Close sessions created in the functional API
Add overriding Content-Length
Note about read timeout errors and max_retries
Add DeprecationWarnings to inform users of plans
Addresses the LocationParseError but not the DecodeError from
kennethreitz#1572. When running
test_requests.py, I got an error in test_session_pickling which resulted
in a TypeError. I'm not sure of the reason for the TypeError but I have
commented out that test.
so sections can be linked from other projects using Intersphinx
RecentlyUsedContainers are threadsafe so they require a lock and as such
cannot be serialized with pickle directly. To handle it, we need to
convert it to a dictionary first and then back when deserializing.

Fixes psf#2345
url was already parsed, don't urlparse twice
Docs: Add more section labels for referencing
Properly serialize RecentlyUsedContainers for cache
Enable GitHub syntax highlighting on README
radarhere and others added 27 commits May 21, 2015 10:25
fix contextlib.closing bug for sessions where content is not consumed…
Allows for sections to be linked from other projects using Intersphinx.
Docs: Add more section labels for referencing
Avoid double releasing chunked upload connections
It seems convenient to include the URL in the error message in case you
get an unexpected error.

E.g.:

    In [1]: import requests

    In [2]: resp = requests.get('http://www.google.com/eofdfdfdfdfd')

    In [3]: resp
    Out[3]: <Response [404]>

    In [4]: resp.raise_for_status()
    ---------------------------------------------------------------------------
    HTTPError                                 Traceback (most recent call last)
    <ipython-input-4-00e7077cfb5b> in <module>()
    ----> 1 resp.raise_for_status()

    /Users/marca/dev/git-repos/requests/requests/models.py in raise_for_status(self)
        835
        836         if http_error_msg:
    --> 837             raise HTTPError(http_error_msg, response=self)
        838
        839     def close(self):

    HTTPError: 404 Client Error: Not Found for url: http://www.google.com/eofdfdfdfdfd
Display URL as part of HTTP error messages
If the netrc file exists but cannot be parsed or read, get_netrc_auth
silently fails.

Add a new argument `ignore_errors` which when set to False will cause
any parse/permission errors to be raised to the caller.  The default
value is True, which means the default behavior is unchanged.

Fixes psf#2654

Change-Id: I7436aaaf593178673ab84fd9e7ab4bcb0e3fe75e
Change-Id: Ib82c7c614edafc15e5db858d9c1b9a73aebd8a95
Allow get_netrc_auth to raise parse/permission errors to caller
Only pass useful timeouts to _get_conn
- Test for NotImplemented in __eq__
- Adds test for copy()
- Adds test for __repr__()
Adds extra tests for CaseInsensitiveDict
Previously this section prefaced an example with:

    For example, we didn't specify our content-type

But, the actual example set a custom user-agent header on the request. This
changes it to say "user-agent" instead which matches the given example.
Fix quickstart "Custom Headers" example intro
@label-hook label-hook Bot added the ai:review Phoenix AI: PR ready for review label Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:review Phoenix AI: PR ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SWE-bench] psf__requests-2674