From 5aa6c8689510413399aa9e994a81012b46d19e04 Mon Sep 17 00:00:00 2001 From: Honza Kral Date: Sun, 14 Jul 2013 15:51:04 +0200 Subject: [PATCH] Make sure we don't blow up on utf-8 str on py2 --- elasticsearch/client/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/elasticsearch/client/utils.py b/elasticsearch/client/utils.py index 919a579a..ad808630 100644 --- a/elasticsearch/client/utils.py +++ b/elasticsearch/client/utils.py @@ -19,7 +19,12 @@ def _escape(part): part = ','.join(part) if isinstance(part, (type(''), type(u''))): # mark ',' as safe for nicer url in logs - return quote_plus(part.encode('utf-8'), ',') + try: + part = part.encode('utf-8') + except UnicodeDecodeError: + # Python 2 and str, no need to re-encode + pass + return quote_plus(part, ',') return str(part) def _escape_param(value):