File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 10
10
import importlib
11
11
import sys
12
12
13
+ # -------
14
+ # urllib3
15
+ # -------
16
+ from urllib3 import __version__ as urllib3_version
17
+
18
+ # Detect which major version of urllib3 is being used.
19
+ try :
20
+ is_urllib3_2 = int (urllib3_version .split ('.' )[0 ]) == 2
21
+ except (TypeError , AttributeError ):
22
+ # If we can't discern a version, prefer old functionality.
23
+ is_urllib3_2 = False
24
+
13
25
# -------------------
14
26
# Character Detection
15
27
# -------------------
Original file line number Diff line number Diff line change 41
41
)
42
42
from .compat import parse_http_list as _parse_list_header
43
43
from .compat import (
44
+ is_urllib3_2 ,
44
45
proxy_bypass ,
45
46
proxy_bypass_environment ,
46
47
quote ,
@@ -136,7 +137,9 @@ def super_len(o):
136
137
total_length = None
137
138
current_position = 0
138
139
139
- if isinstance (o , str ):
140
+ if is_urllib3_2 and isinstance (o , str ):
141
+ # urllib3 2.x treats all strings as utf-8 instead
142
+ # of latin-1 (iso-8859-1) like http.client.
140
143
o = o .encode ("utf-8" )
141
144
142
145
if hasattr (o , "__len__" ):
You can’t perform that action at this time.
0 commit comments