Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py3: tracing logs binary strings #84

Closed
johbo opened this issue May 9, 2014 · 1 comment
Closed

Py3: tracing logs binary strings #84

johbo opened this issue May 9, 2014 · 1 comment

Comments

@johbo
Copy link

johbo commented May 9, 2014

Just noticed a small issue on Python 3.4 when using the tracing logger. It seems to break a little bit due to str vs. bytes issues.

elasticsearch.trace: INFO: curl -XGET 'http://localhost:9200/myindex/mydoc/_search?pretty&size=100&from=0' -d 'b'{"query": {"match_all": {}}}''

The following diff shows how I hacked it in on my box to have nice tracing, but I am not sure if that's the proper way to address it.

diff --git a/elasticsearch/connection/base.py b/elasticsearch/connection/base.py
index 16c0b97..3240e71 100644
--- a/elasticsearch/connection/base.py
+++ b/elasticsearch/connection/base.py
@@ -56,7 +56,7 @@ class Connection(object):
             path = path.replace('?', '?pretty&', 1) if '?' in path else path + '?pretty'
             if self.url_prefix:
                 path = path.replace(self.url_prefix, '', 1)
-            tracer.info("curl -X%s 'http://localhost:9200%s' -d '%s'", method, path, _pretty_json(body) if body else '')
+            tracer.info("curl -X%s 'http://localhost:9200%s' -d '%s'", method, path, _pretty_json(body.decode()) if body else '')

         if tracer.isEnabledFor(logging.DEBUG):
             tracer.debug('#[%s] (%.3fs)\n#%s', status_code, duration, _pretty_json(response).replace('\n', '\n#') if response else '')
@@ -81,5 +81,3 @@ class Connection(object):
             pass

         raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
@honzakral
Copy link
Contributor

Thanks for the catch, fixed in f10d7f2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants