From 0216ae78000f9d88d27134b9920de8075b1c86d8 Mon Sep 17 00:00:00 2001 From: Bruce Adams Date: Tue, 28 Nov 2023 13:17:49 -0500 Subject: [PATCH] Enhance `super_len` to count encoded bytes for str This is a possible fix for issue #6586 --- src/requests/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/requests/utils.py b/src/requests/utils.py index c3b123ea4e..ab982f04e3 100644 --- a/src/requests/utils.py +++ b/src/requests/utils.py @@ -134,7 +134,10 @@ def super_len(o): total_length = None current_position = 0 - if hasattr(o, "__len__"): + if isinstance(o, str): + total_length = len(o.encode("utf-8")) + + elif hasattr(o, "__len__"): total_length = len(o) elif hasattr(o, "len"):