fix: wrap urllib3 DecodeError and TimeoutError exceptions in requests API#102
Open
label-hook[bot] wants to merge 1784 commits into
Open
fix: wrap urllib3 DecodeError and TimeoutError exceptions in requests API#102label-hook[bot] wants to merge 1784 commits into
label-hook[bot] wants to merge 1784 commits into
Conversation
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
Retries logic
Release v2.5.0
Update tests to work offline
Enable GitHub syntax highlighting on README
Fixed typos
Conflicts: test_requests.py
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
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.
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: Wrapsurllib3.exceptions.DecodeErrorand inherits fromRequestExceptionTimeoutError: Wrapsurllib3.exceptions.TimeoutErrorand inherits fromTimeoutModified
requests/adapters.py:DecodeErrorandTimeoutErrorThese 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