Skip to content

Commit a3a52af

Browse files
authored
Merge pull request elastic#652 from brunobell/master
fix: AttributeError: 'bytes' object has no attribute 'encode'(PY3)
2 parents 5c537de + 12be146 commit a3a52af

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

elasticsearch/client/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import weakref
44
from datetime import date, datetime
55
from functools import wraps
6-
from ..compat import string_types, quote_plus
6+
from ..compat import string_types, quote_plus, PY2
77

88
# parts of URL to be omitted
99
SKIP_IN_PATH = (None, '', b'', [], ())
@@ -32,7 +32,10 @@ def _escape(value):
3232

3333
# encode strings to utf-8
3434
if isinstance(value, string_types):
35-
return value.encode('utf-8')
35+
if PY2 and isinstance(value, unicode):
36+
return value.encode('utf-8')
37+
if not PY2 and isinstance(value, str):
38+
return value.encode('utf-8')
3639

3740
return str(value)
3841

0 commit comments

Comments
 (0)