Skip to content

fix: handle bytes objects properly in builtin_str for Python 3#83

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

fix: handle bytes objects properly in builtin_str for Python 3#83
label-hook[bot] wants to merge 1522 commits into
mainfrom
phoenix/issue-82

Conversation

@label-hook

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

Copy link
Copy Markdown

Summary

Fixes 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 HTTP requests to fail with 404 errors when method names were passed as bytes objects in Python 3.

Changes

  • Modified builtin_str() function in requests/compat.py to detect bytes objects in Python 3 and decode them using UTF-8 encoding
  • Maintains backward compatibility with Python 2 where bytes and str are the same type
  • Now properly converts b'GET' to 'GET' instead of "b'GET'"

Testing

  • Verified that builtin_str(b'GET') returns 'GET' in Python 3
  • Confirmed that builtin_str('GET') still returns 'GET' (no regression)
  • Tested that HTTP methods work correctly when passed as bytes objects
  • Ensured backward compatibility is maintained
  • Baseline test suite status unchanged (no new failures introduced)

Closes #82


Closes #82

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 26 commits October 6, 2014 05:40
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 13, 2026
@kkipngenokoech kkipngenokoech force-pushed the main branch 2 times, most recently from 36453b9 to a0df2cb Compare April 18, 2026 16:21
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