resolved RESOLVED PASS · 57 tool calls · 267 s · psf/requests
Fix `prepare_body` stream detection for `__getattr__`-based file wrappers
Resolves #7432 .
Add `hasattr(data, "__iter__")` as a fallback stream detector:
```python
if (
isinstance(data, Iterable) or hasattr(data, "__iter__")
) and not isinstance(data, (str, bytes, list, tuple, Mapping)):
```
This catches file-like objects that proxy their interface through `__getattr__`, restoring the 2.33.1 behavior without reverting the isinstance(Iterable) modernization for standard iterables.| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"prepare_body\" src/requests | head -20"
} | {"status": "ok", "stdout": "src/requests/models.py:442: self.prepare_body(data, files, json)\nsrc/requests/models.py:574: def prepare_body(\n", "stderr": "", "efull{"status": "ok", "stdout": "src/requests/models.py:442: self.prepare_body(data, files, json)\nsrc/requests/models.py:574: def prepare_body(\n", "stderr": "", "exit_code": 0} |
| 2 | run_command | {
"command": "sed -n '574,650p' src/requests/models.py"
} | {"status": "ok", "stdout": " def prepare_body(\n self, data: _t.DataType, files: _t.FilesType, json: _t.JsonType = None\n ) -> None:\n \"\"\"Prepares the given full{"status": "ok", "stdout": " def prepare_body(\n self, data: _t.DataType, files: _t.FilesType, json: _t.JsonType = None\n ) -> None:\n \"\"\"Prepares the given HTTP body data.\"\"\"\n\n # Check if file, fo, generator, iterator.\n # If not, run through normal process.\n\n # Nottin' on you.\n body = None\n content_type = None\n\n if not data and json is not None:\n # urllib3 requires a bytes-like body. Python 2's json.dumps\n # provides this natively, but Python 3 gives a Unicode string.\n content_type = \"application/json\"\n\n try:\n body = complexjson.dumps(json, allow_nan=False)\n except ValueError as ve:\n raise InvalidJSONError(ve, request=self)\n\n if not isinstance(body, bytes):\n body = body.encode(\"utf-8\")\n\n if isinstance(data, Iterable) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):\n try:\n length = super_len(data)\n except (TypeError, AttributeError, UnsupportedOperation):\n length = None\n\n body = data\n\n if getattr(body, \"tell\", None) is not None:\n # Record the current file position before reading.\n # This will allow us to rewind a file in the event\n # of a redirect.\n try:\n self._body_position = body.tell() # type: ignore[union-attr] # guarded by getattr check\n except OSError:\n # This differentiates from None, allowing us to catch\n # a failed `tell()` later when trying to rewind the body\n self._body_position = object()\n\n if files:\n raise NotImplementedError(\n \"Streamed bodies and files are mutually exclusive.\"\n )\n\n if le |
| 3 | run_command | {
"command": "grep -n \"from collections.abc import Iterable\" src/requests/models.py || grep -n \"from typing import Iterable\" src/requests/models.py"
} | {"status": "error", "error_type": "CommandError", "error_message": "", "details": {"stdout": "", "stderr": "", "exit_code": 1}}full{"status": "error", "error_type": "CommandError", "error_message": "", "details": {"stdout": "", "stderr": "", "exit_code": 1}} |
| 4 | run_command | {
"command": "head -n 100 src/requests/models.py"
} | {"status": "ok", "stdout": "\"\"\"\nrequests.models\n~~~~~~~~~~~~~~~\n\nThis module contains the primary objects that power Requests.\n\"\"\"\n\nfrom __future__full{"status": "ok", "stdout": "\"\"\"\nrequests.models\n~~~~~~~~~~~~~~~\n\nThis module contains the primary objects that power Requests.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport datetime\n\n# Import encoding now, to avoid implicit import later.\n# Implicit import within threads may cause LookupError when standard library is in a ZIP,\n# such as in Embedded Python. See https://github.com/psf/requests/issues/3578.\nimport encodings.idna # noqa: F401 # type: ignore[reportUnusedImport]\nfrom collections.abc import Callable, Generator, Iterable, Iterator, Mapping\nfrom io import UnsupportedOperation\nfrom typing import (\n TYPE_CHECKING,\n Any,\n Final,\n Literal,\n cast,\n overload,\n)\n\nfrom urllib3.exceptions import (\n DecodeError,\n LocationParseError,\n ProtocolError,\n ReadTimeoutError,\n SSLError,\n)\nfrom urllib3.fields import RequestField\nfrom urllib3.filepost import encode_multipart_formdata\nfrom urllib3.util import parse_url\n\nfrom ._internal_utils import to_native_string, unicode_is_ascii\nfrom ._types import SupportsRead as _SupportsRead\nfrom .auth import HTTPBasicAuth\nfrom .compat import (\n JSONDecodeError,\n basestring,\n builtin_str,\n chardet,\n cookielib,\n urlencode,\n urlsplit,\n urlunparse,\n)\nfrom .compat import json as complexjson\nfrom .cookies import (\n _copy_cookie_jar, # type: ignore[reportPrivateUsage]\n cookiejar_from_dict,\n get_cookie_header,\n)\nfrom .exceptions import (\n ChunkedEncodingError,\n ConnectionError,\n ContentDecodingError,\n HTTPError,\n InvalidJSONError,\n InvalidURL,\n MissingSchema,\n StreamConsumedError,\n)\nfrom .exceptions import JSONDecodeError as RequestsJSONDecodeError\nfrom .exceptions import SSLError as RequestsSSLError\nfrom .hooks import default_hooks\nfrom .status_codes import codes\nfrom .structures import CaseInsensitiveDict\nfrom .utils import (\n check_header_validity,\n get_auth_from_url, |
| 5 | edit_file | {
"filepath": "src/requests/models.py",
"new_string": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):",
"old_string": " if isinstance(data, Iterable) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):"
} | {"status": "ok", "filepath": "src/requests/models.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/src/requests/models.py\n+++ b/src/requests/models.pfull{"status": "ok", "filepath": "src/requests/models.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/src/requests/models.py\n+++ b/src/requests/models.py\n@@ -596,7 +596,7 @@\n if not isinstance(body, bytes):\n body = body.encode(\"utf-8\")\n \n- if isinstance(data, Iterable) and not isinstance(\n+ if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):\n try:\n", "is_truncated": false} |
| 6 | run_command | {
"command": "python3 -c \"from collections.abc import Iterable; class Proxy: def __getattr__(self, name): if name == '__iter__': return lambda: iter([1, 2, 3]); print(isinstance(Proxy(), Iterable), hasattr(Proxy(), '__iter__'))\""
} | {"status": "error", "error_type": "CommandError", "error_message": " File \"<string>\", line 1\n from collections.abc import Iterable; class Proxy: def __getattfull{"status": "error", "error_type": "CommandError", "error_message": " File \"<string>\", line 1\n from collections.abc import Iterable; class Proxy: def __getattr__(self, name): if name == '__iter__': return lambda: iter([1, 2, 3]); print(isinstance(Proxy(), Iterable), hasattr(Proxy(), '__iter__'))\n ^^^^^\nSyntaxError: invalid syntax\n", "details": {"stdout": "", "stderr": " File \"<string>\", line 1\n from collections.abc import Iterable; class Proxy: def __getattr__(self, name): if name == '__iter__': return lambda: iter([1, 2, 3]); print(isinstance(Proxy(), Iterable), hasattr(Proxy(), '__iter__'))\n ^^^^^\nSyntaxError: invalid syntax\n", "exit_code": 1}} |
| 7 | run_command | {
"command": "python3 -c \"from collections.abc import Iterable; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\nprint(isinstance(Proxy(), Iterable), hasattr(Proxy(), '__iter__'))\""
} | {"status": "ok", "stdout": "False True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "False True\n", "stderr": "", "exit_code": 0} |
| 8 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; from collections.abc import Mapping; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\npr = PreparedRequest()\npr.prepare_body(Proxy(), None, None)\nprint(f'Body is Proxy: {pr.body is Proxy()}')\""
} | {"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from requests.full{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from requests.models import PreparedRequest; from collections.abc import Mapping;\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workspace/src/requests/__init__.py\", line 171, in <module>\n from .api import delete, get, head, options, patch, post, put, request\n File \"/workspace/src/requests/api.py\", line 15, in <module>\n from . import sessions\n File \"/workspace/src/requests/sessions.py\", line 21, in <module>\n from .adapters import HTTPAdapter\n File \"/workspace/src/requests/adapters.py\", line 51, in <module>\n from .models import Response\n File \"/workspace/src/requests/models.py\", line 599\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n ^\nSyntaxError: unexpected character after line continuation character\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from requests.models import PreparedRequest; from collections.abc import Mapping;\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workspace/src/requests/__init__.py\", line 171, in <module>\n from .api import delete, get, head, options, patch, post, put, request\n File \"/workspace/src/requests/api.py\", line 15, in <module>\n from . import sessions\n File \"/workspace/src/requests/sessions.py\", line 21, in <module>\n from .adapters import HTTPAdapter\n File \"/workspace/src/requests/adapters.py\", line 51, in <module>\n from .models import Response\n File \"/workspace/src/requests/models.py\", line 599\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n ^\nSyntaxError: unexpected character after line continuation character\n", "exit_cod |
| 9 | run_command | {
"command": "sed -n '590,605p' src/requests/models.py"
} | {"status": "ok", "stdout": "\n try:\n body = complexjson.dumps(json, allow_nan=False)\n except ValueError as ve:\n raise InvalidJSONError(ve, request=self)\n\n full{"status": "ok", "stdout": "\n try:\n body = complexjson.dumps(json, allow_nan=False)\n except ValueError as ve:\n raise InvalidJSONError(ve, request=self)\n\n if not isinstance(body, bytes):\n body = body.encode(\"utf-8\")\n\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):\n try:\n length = super_len(data)\n except (TypeError, AttributeError, UnsupportedOperation):\n length = None\n", "stderr": "", "exit_code": 0} |
| 10 | edit_file | {
"filepath": "src/requests/models.py",
"new_string": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):",
"old_string": " if (isinstance(data, Iterable) or hasattr(data, \\\\\\\\\\\\\\\"__iter__\\\\\\\\\\\\\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):"
} | {"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly andfull{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."} |
| 11 | edit_file | {
"filepath": "src/requests/models.py",
"new_string": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):",
"old_string": " if (isinstance(data, Iterable) or hasattr(data, \\\\\\\"__iter__\\\\\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):"
} | {"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly andfull{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."} |
| 12 | run_command | {
"command": "sed -n '596,600p' src/requests/models.py"
} | {"status": "ok", "stdout": " if not isinstance(body, bytes):\n body = body.encode(\"utf-8\")\n\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\full{"status": "ok", "stdout": " if not isinstance(body, bytes):\n body = body.encode(\"utf-8\")\n\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n", "stderr": "", "exit_code": 0} |
| 13 | edit_file | {
"filepath": "src/requests/models.py",
"new_string": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):",
"old_string": " if (isinstance(data, Iterable) or hasattr(data, \\\\\\\\\\\\\\\"__iter__\\\\\\\\\\\\\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):"
} | {"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly andfull{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."} |
| 14 | run_command | {
"command": "cat -A src/requests/models.py | sed -n '598p'"
} | {"status": "ok", "stdout": "$\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "$\n", "stderr": "", "exit_code": 0} |
| 15 | run_command | {
"command": "cat -A src/requests/models.py | sed -n '599p'"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance($\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance($\n", "stderr": "", "exit_code": 0} |
| 16 | run_command | {
"command": "sed -n '598,601p' src/requests/models.py"
} | {"status": "ok", "stdout": "\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)full{"status": "ok", "stdout": "\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):\n", "stderr": "", "exit_code": 0} |
| 17 | edit_file | {
"filepath": "src/requests/models.py",
"new_string": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):",
"old_string": " if (isinstance(data, Iterable) or hasattr(data, \\\\\\\"\\\\\\\"\\\\\\\"__iter__\\\\\\\"\\\\\\\"\\\\\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):"
} | {"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly andfull{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."} |
| 18 | run_command | {
"command": "sed -n '598,601p' src/requests/models.py | cat -A"
} | {"status": "ok", "stdout": "$\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance($\n data, (str, bytes, list, tuple, Mappinfull{"status": "ok", "stdout": "$\n if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance($\n data, (str, bytes, list, tuple, Mapping)$\n ):$\n", "stderr": "", "exit_code": 0} |
| 19 | edit_file | {
"filepath": "src/requests/models.py",
"new_string": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):",
"old_string": " if (isinstance(data, Iterable) or hasattr(data, \\\\\\\"\\\\\\\"\\\\\\\"__iter__\\\\\\\"\\\\\\\"\\\\\\\")) and not isinstance(\n data, (str, bytes, list, tuple, Mapping)\n ):"
} | {"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly andfull{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."} |
| 20 | run_command | {
"command": "sed -i '599s/\\\\\\\\\\\\\\\\\\\\\\\"__iter__\\\\\\\\\\\\\\\\\\\\\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 21 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n", "stderr": "", "exit_code": 0} |
| 22 | run_command | {
"command": "sed -i '599s/\\\\\\\\\\\\\\\"__iter__\\\\\\\\\\\\\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 23 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n", "stderr": "", "exit_code": 0} |
| 24 | run_command | {
"command": "sed -i '599s/\\\\\\\\\\\"__iter__\\\\\\\\\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 25 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \\\"__iter__\\\")) and not isinstance(\n", "stderr": "", "exit_code": 0} |
| 26 | run_command | {
"command": "sed -i '599s/\\\\\\\"__iter__\\\\\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 27 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0} |
| 28 | run_command | {
"command": "sed -i '599s/\\\\\\\"__iter__\\\\\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 29 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0} |
| 30 | run_command | {
"command": "sed -i '599s/\\\"__iter__\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 31 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0} |
| 32 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; from collections.abc import Mapping; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\npr = PreparedRequest()\npr.prepare_body(Proxy(), None, None)\nprint(f'Body is Proxy: {pr.body is Proxy()}')\""
} | {"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 9, in <module>\n pr.prepare_bodfull{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 9, in <module>\n pr.prepare_body(Proxy(), None, None)\n ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^\n File \"/workspace/src/requests/models.py\", line 628, in prepare_body\n self.headers[\"Transfer-Encoding\"] = \"chunked\"\n ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^\nTypeError: 'NoneType' object does not support item assignment\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"<string>\", line 9, in <module>\n pr.prepare_body(Proxy(), None, None)\n ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^\n File \"/workspace/src/requests/models.py\", line 628, in prepare_body\n self.headers[\"Transfer-Encoding\"] = \"chunked\"\n ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^\nTypeError: 'NoneType' object does not support item assignment\n", "exit_code": 1}} |
| 33-34 ×2 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; from collections.abc import Mapping; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\npr = PreparedRequest()\npr.headers = {}\npr.prepare_body(Proxy(), None, None)\nprint(f'Body is Proxy: {pr.body is Proxy()}')\""
} | {"status": "ok", "stdout": "Body is Proxy: False\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Body is Proxy: False\n", "stderr": "", "exit_code": 0} |
| 35 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0} |
| 36 | run_command | {
"command": "python3 -c \"import requests.models; print(requests.models.PreparedRequest)\""
} | {"status": "ok", "stdout": "<class 'requests.models.PreparedRequest'>\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "<class 'requests.models.PreparedRequest'>\n", "stderr": "", "exit_code": 0} |
| 37 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\npr = PreparedRequest()\npr.headers = {}\npr.prepare_body(Proxy(), None, None)\nprint(f'Body is Proxy: {pr.body is Proxy()}')\""
} | {"status": "ok", "stdout": "Body is Proxy: False\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Body is Proxy: False\n", "stderr": "", "exit_code": 0} |
| 38 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\npr = PreparedRequest()\npr.headers = {}\npr.prepare_body(Proxy(), None, None)\nprint(f'Body: {type(pr.body)}')\""
} | {"status": "ok", "stdout": "Body: <class '__main__.Proxy'>\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Body: <class '__main__.Proxy'>\n", "stderr": "", "exit_code": 0} |
| 39 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\npr = PreparedRequest()\npr.headers = {}\npr.prepare_body(Proxy(), None, None)\nprint(f'Body is Proxy: {pr.body is Proxy()}')\""
} | {"status": "ok", "stdout": "Body is Proxy: False\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Body is Proxy: False\n", "stderr": "", "exit_code": 0} |
| 40-41 ×2 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\np = Proxy()\npr = PreparedRequest()\npr.headers = {}\npr.prepare_body(p, None, None)\nprint(f'Body is Proxy: {pr.body is p}')\""
} | {"status": "ok", "stdout": "Body is Proxy: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Body is Proxy: True\n", "stderr": "", "exit_code": 0} |
| 42 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0} |
| 43 | run_command | {
"command": "sed -n '599p' src/requests/models.py | cat -A"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0} |
| 44 | run_command | {
"command": "sed -i '599s/\\\\\\\"__iter__\\\\\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 45 | run_command | {
"command": "sed -n '599p' src/requests/models.py | cat -A"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0} |
| 46 | run_command | {
"command": "sed -i '599s/\\\"__iter__\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 47 | run_command | {
"command": "sed -n '599p' src/requests/models.py | cat -A"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0} |
| 48 | run_command | {
"command": "sed -i '599s/\\\\\\\"__iter__\\\\\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 49 | run_command | {
"command": "sed -n '599p' src/requests/models.py | cat -A"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0} |
| 50 | run_command | {
"command": "sed -i '599s/\\\"__iter__\\\"/\"__iter__\"/' src/requests/models.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0, "budget_warning": "Only 10 tool call(s) remaining (50/60 used). Finalize your edits and call submitfull{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0, "budget_warning": "Only 10 tool call(s) remaining (50/60 used). Finalize your edits and call submit_patch soon."} |
| 51 | run_command | {
"command": "sed -n '599p' src/requests/models.py | cat -A"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0, "budget_warnifull{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance($\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 9 tool call(s) remaining (51/60 used). Finalize your edits and call submit_patch soon."} |
| 52 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\np = Proxy()\npr = PreparedRequest()\npr.headers = {}\npr.prepare_body(p, None, None)\nprint(f'Body is Proxy: {pr.body is p}')\""
} | {"status": "ok", "stdout": "Body is Proxy: True\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 8 tool call(s) remaining (52/60 used). Finalize your efull{"status": "ok", "stdout": "Body is Proxy: True\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 8 tool call(s) remaining (52/60 used). Finalize your edits and call submit_patch soon."} |
| 53 | run_command | {
"command": "sed -n '599p' src/requests/models.py"
} | {"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0, "budget_warninfull{"status": "ok", "stdout": " if (isinstance(data, Iterable) or hasattr(data, \"__iter__\")) and not isinstance(\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 7 tool call(s) remaining (53/60 used). Finalize your edits and call submit_patch soon."} |
| 54 | run_command | {
"command": "python3 -c \"import requests.models; print(requests.models.PreparedRequest)\""
} | {"status": "ok", "stdout": "<class 'requests.models.PreparedRequest'>\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 6 tool call(s) remaining (54/60 full{"status": "ok", "stdout": "<class 'requests.models.PreparedRequest'>\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 6 tool call(s) remaining (54/60 used). Finalize your edits and call submit_patch soon."} |
| 55 | run_command | {
"command": "python3 -c \"from requests.models import PreparedRequest; \nclass Proxy: \n def __getattr__(self, name): \n if name == '__iter__': \n return lambda: iter([1, 2, 3])\n raise AttributeError(name)\n\np = Proxy()\npr = PreparedRequest()\npr.headers = {}\npr.prepare_body(p, None, None)\nprint(f'Body is Proxy: {pr.body is p}')\""
} | {"status": "ok", "stdout": "Body is Proxy: True\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 5 tool call(s) remaining (55/60 used). Finalize your efull{"status": "ok", "stdout": "Body is Proxy: True\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 5 tool call(s) remaining (55/60 used). Finalize your edits and call submit_patch soon."} |
| 56 | run_command | {
"command": "cd /workspace && git status --short && git diff --stat"
} | {"status": "ok", "stdout": " M src/requests/models.py\n src/requests/models.py | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n", "stderr": "", "exit_cofull{"status": "ok", "stdout": " M src/requests/models.py\n src/requests/models.py | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n", "stderr": "", "exit_code": 0, "budget_warning": "Only 4 tool call(s) remaining (56/60 used). Finalize your edits and call submit_patch soon."} |
| 57 | run_command | {
"command": "python3 -c \"import requests.models\""
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0, "budget_warning": "Only 3 tool call(s) remaining (57/60 used). Finalize your edits and call submit_full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0, "budget_warning": "Only 3 tool call(s) remaining (57/60 used). Finalize your edits and call submit_patch soon."} |
| 58 | submit_patch | {} | {"status": "ok", "patch_size": 560, "files_changed": 1}full{"status": "ok", "patch_size": 560, "files_changed": 1} |
diff --git a/src/requests/models.py b/src/requests/models.py
index 4142f2a4..f2b6b318 100644
--- a/src/requests/models.py
+++ b/src/requests/models.py
@@ -596,7 +596,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
if not isinstance(body, bytes):
body = body.encode("utf-8")
- if isinstance(data, Iterable) and not isinstance(
+ if (isinstance(data, Iterable) or hasattr(data, "__iter__")) and not isinstance(
data, (str, bytes, list, tuple, Mapping)
):
try:
........................................................................ [ 21%]
.................................................spytest-httpbin server hit an exception serving request: [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1032)
attempting to ignore so the rest of the tests can run
...................... [ 42%]
........................................................................ [ 63%]
........................x............................................... [ 84%]
................................................... [100%]
=============================== warnings summary ===============================
../../../../../../kaggle/tmp/envs/requests/lib/python3.13/site-packages/_pytest/config/__init__.py:1464
/kaggle/tmp/envs/requests/lib/python3.13/site-packages/_pytest/config/__init__.py:1464: PytestConfigWarning: Unknown config option: timeout
self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")
tests/test_requests.py::TestRequests::test_set_basicauth[42-42]
tests/test_requests.py::TestRequests::test_set_basicauth[42-42]
/tmp/swe_work/eval8_submission_v1l/requests_7433/b/workspace/src/requests/auth.py:45: DeprecationWarning: Non-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (42) to a string or bytes object in the near future to avoid problems.
warnings.warn(
tests/test_requests.py::TestRequests::test_set_basicauth[42-42]
tests/test_requests.py::TestRequests::test_set_basicauth[42-42]
/tmp/swe_work/eval8_submission_v1l/requests_7433/b/workspace/src/requests/auth.py:55: DeprecationWarning: Non-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (<class 'int'>) to a string or bytes object in the near future to avoid problems.
warnings.warn(
tests/test_requests.py::TestRequests::test_set_basicauth[None-None]
tests/test_requests.py::TestRequests::test_set_basicauth[None-None]
/tmp/swe_work/eval8_submission_v1l/requests_7433/b/workspace/src/requests/auth.py:45: DeprecationWarning: Non-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (None) to a string or bytes object in the near future to avoid problems.
warnings.warn(
tests/test_requests.py::TestRequests::test_set_basicauth[None-None]
tests/test_requests.py::TestRequests::test_set_basicauth[None-None]
/tmp/swe_work/eval8_submission_v1l/requests_7433/b/workspace/src/requests/auth.py:55: DeprecationWarning: Non-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (<class 'NoneType'>) to a string or bytes object in the near future to avoid problems.
warnings.warn(
tests/test_requests.py::TestPreparingURLs::test_different_connection_pool_for_tls_settings_verify_True
tests/test_requests.py::TestPreparingURLs::test_different_connection_pool_for_tls_settings_verify_bundle_expired_cert
tests/test_requests.py::TestPreparingURLs::test_different_connection_pool_for_tls_settings_verify_bundle_unexpired_cert
tests/test_requests.py::TestPreparingURLs::test_different_connection_pool_for_mtls_settings
/kaggle/tmp/envs/requests/lib/python3.13/site-packages/urllib3/connectionpool.py:1129: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
337 passed, 1 skipped, 1 xfailed, 13 warnings in 38.97s
[2026-09-26 02:08:51,493] WARNING in core: flasgger is not installed; serving the static landing page at / and skipping the Swagger UI and /spec.json.