From a5e64000f489b059a5aca9463afd9f39b1c5b273 Mon Sep 17 00:00:00 2001 From: Chris Riches Date: Thu, 9 Apr 2026 13:39:35 +0000 Subject: [PATCH] Clarify decode_unicode behaviour in iter_{content,lines} docstrings This corner case around automatic encoding detection is already mentioned in the "Advanced Usage" documentation, but deserves to be in the docstring too. --- src/requests/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/requests/models.py b/src/requests/models.py index 2d043f59cf..e158b6cca2 100644 --- a/src/requests/models.py +++ b/src/requests/models.py @@ -811,8 +811,10 @@ def iter_content(self, chunk_size=1, decode_unicode=False): chunks are received. If stream=False, data is returned as a single chunk. - If decode_unicode is True, content will be decoded using the best - available encoding based on the response. + If decode_unicode is True, content will be decoded using encoding + information from the response. If no encoding information is available, + bytes will be returned. This can be bypassed by manually setting + `encoding` on the response. """ def generate(): @@ -863,6 +865,9 @@ def iter_lines( stream=True is set on the request, this avoids reading the content at once into memory for large responses. + The decode_unicode param works the same as in `iter_content`, with the + same caveats. + .. note:: This method is not reentrant safe. """