Skip to content

Commit 0216ae7

Browse files
committed
Enhance super_len to count encoded bytes for str
This is a possible fix for issue #6586
1 parent f670704 commit 0216ae7

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/requests/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ def super_len(o):
134134
total_length = None
135135
current_position = 0
136136

137-
if hasattr(o, "__len__"):
137+
if isinstance(o, str):
138+
total_length = len(o.encode("utf-8"))
139+
140+
elif hasattr(o, "__len__"):
138141
total_length = len(o)
139142

140143
elif hasattr(o, "len"):

0 commit comments

Comments
 (0)