Fix: AttributeError: 'bytes' object has no attribute 'encode'(PY3)

This commit is contained in:
broono
2017-10-09 13:47:36 +08:00
parent 5c537deca4
commit 12be146e45
+5 -2
View File
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import weakref
from datetime import date, datetime
from functools import wraps
from ..compat import string_types, quote_plus
from ..compat import string_types, quote_plus, PY2
# parts of URL to be omitted
SKIP_IN_PATH = (None, '', b'', [], ())
@@ -32,7 +32,10 @@ def _escape(value):
# encode strings to utf-8
if isinstance(value, string_types):
return value.encode('utf-8')
if PY2 and isinstance(value, unicode):
return value.encode('utf-8')
if not PY2 and isinstance(value, str):
return value.encode('utf-8')
return str(value)