Files
app-store-optimization/skills/loki-mode/benchmarks/results/2026-01-05-01-24-17/swebench-patches/psf__requests-2317.patch

54 lines
2.0 KiB
Diff

Now I understand the issue and the fix. The problem was that in the old version of requests (2.4.3), there was a line:
```python
method = builtin_str(method)
```
When `method` is a bytes string like `b'GET'` and you call `str(b'GET')` in Python 3, you get the literal string `"b'GET'"` instead of `"GET"`.
The fix is to use `to_native_string(method)` which properly handles both string and bytes types by decoding bytes to strings when necessary.
Looking at the issue, the bug was in `requests/sessions.py`. The hint says this should use `to_native_str` (which is called `to_native_string` in the actual code).
Let me create the patch for the version 2.4.3 of requests. Based on the issue, the problematic line was in `requests/sessions.py`:
```python
method = builtin_str(method)
```
This should be replaced with:
```python
method = to_native_string(method)
```
And the import needs to be added as well. Let me construct the patch for the requests 2.4.3 version:
--- a/requests/sessions.py
+++ b/requests/sessions.py
@@ -9,7 +9,7 @@ import os
from collections import Mapping
from datetime import datetime
-from .compat import cookielib, OrderedDict, urljoin, urlparse, builtin_str
+from .compat import cookielib, OrderedDict, urljoin, urlparse
from .cookies import (
cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies)
from .models import Request, PreparedRequest, DEFAULT_REDIRECT_LIMIT
@@ -17,6 +17,7 @@ from .hooks import default_hooks, dispatch_hook
from .utils import to_key_val_list, default_headers
from .exceptions import TooManyRedirects, InvalidSchema
from .structures import CaseInsensitiveDict
+from .utils import to_native_string
from .adapters import HTTPAdapter
@@ -425,7 +426,7 @@ class Session(SessionRedirectMixin):
:param cert: (optional) if String, path to ssl client cert file (.pem).
If Tuple, ('cert', 'key') pair.
"""
- method = builtin_str(method)
+ method = to_native_string(method, 'utf-8')
# Create the Request.
req = Request(