Skip to content

fix: make iter_content with decode_unicode=True return unicode strings#104

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

fix: make iter_content with decode_unicode=True return unicode strings#104
label-hook[bot] wants to merge 2258 commits into
mainfrom
phoenix/issue-103

Conversation

@label-hook

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

Copy link
Copy Markdown

Summary

Fixes an issue where iter_content(decode_unicode=True) was returning bytes instead of unicode strings, making it inconsistent with the text property behavior. When decode_unicode=True is specified, users expect to receive unicode strings, not bytes.

Changes

  • Modified the iter_content method in requests/models.py to properly decode bytes to unicode when decode_unicode=True
  • Added logic to use the existing stream_decode_response_unicode utility function for consistent unicode decoding
  • Ensured backward compatibility by maintaining existing behavior when decode_unicode=False (default)

Testing

The fix was verified through manual testing that confirms:

  • iter_content(decode_unicode=True) now returns unicode strings instead of bytes
  • iter_content(decode_unicode=False) continues to return bytes as expected
  • The decoded content from iter_content(decode_unicode=True) matches the content from the text property
  • Behavior is consistent across different content types including application/json

Closes #103


Closes #103

Lukasa and others added 30 commits December 28, 2015 15:58
advanced: use "client.*" to designate client certificate
…x_theme

Switch to alabaster sphinx theme in the docs
distutils has been deprecated for years now and pip is refusing to install
projects using it. As such, *some* users are reporting problems installing
requests. Let's avoid this entirely by not falling back to distutils at all.
Stop falling back to distutils in setup.py
Return request & response with TooManyRedirects
Fix api doc of debug logging for Python 3
Warn about encrypted keys in the docs.
Brett Higgins and others added 27 commits May 13, 2016 15:30
It seems it's necessary both in pulling all_proxy from the environment
(rebuild_proxies) and deciding which proxy to use (select_proxy).

Also added new functional test.
Fix to check for Plain ip notations in no_proxy settings if not CIDR
So that failing tests don't cause the server thread to hang
indefinitely, waiting for connections that will never come.

Rationale for suppressing error/traceback from interrupted
_accept_connection in testserver.Server:
https://gist.github.com/brettdh/b6e741227b2297f19d2118077f14dfa5

* Move server socket close to just before join

This way it handles the no-connections, no-exceptions case
as well as the exception case. If the server thread doesn't
exit by itself within 5 seconds of the context manager exit,
the accept will be interrupted.

* Address feedback

- pytest.raises rather than except:pass
- Move socket create/bind back to run()
- Timeout on accepting connections
Encoding JSON requests to bytes for urllib3 to handle
* BaseAdapter definition of send is missing mandatory params

* Copy over relevant parts of the interface documentation

* Indentation fix

* Change base class documentation for close
This is only a minor improvement on the great work of
https://github.com/kennethreitz/requests/pull/2859 that permits to run
tests on hosts without Internet connection.
Update documentation of Session.max_redirects
Verify that the expected warnings are emitted
with SubjectAltNameWarning emitted on all environments
due to the https server provided by httpbin_secure.
Use xfail marker for a test expected to fail without Internet connection
Update list of supported Python versions in todo.rst
@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-3362