Skip to content

fix: properly decode binary strings in builtin_str function#95

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

fix: properly decode binary strings in builtin_str function#95
label-hook[bot] wants to merge 1522 commits into
mainfrom
phoenix/issue-94

Conversation

@label-hook

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

Copy link
Copy Markdown

Summary

Fixes an issue where binary string HTTP methods like b'GET' were being converted to their string representation "b'GET'" instead of being properly decoded to 'GET'. This caused 404 Not Found responses when using libraries that encode method names as binary strings.

Changes

  • Modified builtin_str() function in requests/compat.py to detect binary strings and decode them using UTF-8 encoding
  • Added proper handling for both Python 2 and Python 3 compatibility
  • Binary strings like b'GET' are now correctly converted to 'GET' instead of "b'GET'"
  • Regular strings continue to work as before

Testing

The fix was verified to handle binary string methods correctly:

  • b'GET''GET'
  • b'POST''POST'
  • Regular strings like 'GET' continue to work unchanged
  • Maintains compatibility across Python versions

Baseline test suite results were unchanged, confirming no regressions were introduced.

Closes #94


Closes #94

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 15, 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