Skip to content

fix: handle bytes objects properly in builtin_str function#100

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

fix: handle bytes objects properly in builtin_str function#100
label-hook[bot] wants to merge 1522 commits into
mainfrom
phoenix/issue-99

Conversation

@label-hook

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

Copy link
Copy Markdown

Summary

Fixes an issue where builtin_str() incorrectly converts bytes objects like b'GET' to their string representation "b'GET'" instead of decoding them to the actual string 'GET'. This was causing 404 errors when HTTP methods were passed as bytes objects.

Changes

  • Modified builtin_str() in requests/compat.py to detect bytes objects and decode them using UTF-8 encoding
  • Maintains backward compatibility for all other data types
  • The function now properly handles the case where libraries like python-neutronclient pass binary-encoded method names

Testing

The fix was verified to handle:

  • Bytes objects like b'GET' are properly decoded to 'GET'
  • Regular strings are passed through unchanged
  • Other data types continue to work as before
  • Resolves the 404 error scenario described in the issue

Baseline test suite results show no new test failures introduced by this change.

Closes #99


Closes #99

Kenneth Reitz and others added 30 commits April 26, 2014 09:28
Don't repopulate proxies if we don't trust the environment.
There's not a lot of good reason to actually call out easy_install at all.
Anyone who prefers it already knows it exists and everyone else should be
directed unambiguously towards pip.
Remove the easy_install section
ImportError: No module named 'requests.packages.urllib3.util'
Improved decoding support for Response.iter_content and iter_lines
Add __str__ to case insensitive dict
Catch errors while handling redirects
`Sesssion` -> `Session`
Fix typo in advanced.rst docs
kennethreitz and others added 27 commits October 6, 2014 05:39
Re-order params for backwards compat
Fixed -2250
Fix issue psf#2279. "Gittip" changed to "Gratipay". Tip button extended from 48px to 60px.
Fix psf#2288 . Change urllib3 and chardet workflow
Adding a custom line delimiter to iter_lines()
…e_unicode_url

Fix failing test test_prepare_unicode_url
@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-2317