Skip to content

fix: handle binary strings properly in builtin_str function#68

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

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

Conversation

@label-hook

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

Copy link
Copy Markdown

Summary

Fixes an issue where binary strings like b'GET' were being converted to their string representation "b'GET'" instead of being properly decoded to 'GET'. This caused HTTP requests to fail with 404 errors when method names were passed as binary strings.

Changes

  • Modified builtin_str() function in requests/compat.py to detect binary strings (bytes) and decode them using UTF-8 encoding
  • Maintains backward compatibility for regular strings, integers, and other types
  • Ensures HTTP method names work correctly regardless of whether they're passed as strings or binary strings

Testing

The fix was verified to handle:

  • Binary strings like b'GET' are properly decoded to 'GET'
  • Regular strings remain unchanged
  • Other types (int, None, etc.) are converted to strings as before
  • Integration with sessions.py ensures HTTP methods work correctly when passed as binary strings

Closes #67


Closes #67

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