Benoss / django-elasticsearch-debug-toolbar

A Django Debug Toolbar panel for Elasticsearch
https://pypi.python.org/pypi/django-elasticsearch-debug-toolbar/
MIT License
29 stars 19 forks source link

ElasticQueryInfo.__init__ fails in Python 3 #4

Closed pquentin closed 9 years ago

pquentin commented 9 years ago

As you can see in Transform.perform_request from the Python elasticsearch client, body is specifically encoded to bytes. However, full_url is a Unicode str.

    def __init__(self, method, full_url, path, body, status_code, response, duration):
        self.method = method
        self.full_url = full_url
        self.path = path
        self.body = _pretty_json(body)
        self.status_code = status_code
        self.response = _pretty_json(response)
        self.duration = round(duration * 1000, 2)
>       self.hash = hashlib.md5(self.full_url + self.body).hexdigest()
E       TypeError: Can't convert 'bytes' object to str implicitly

Since hashlib.md5() expects bytes, you need to encode self.full_url too using self.full_url.encode('ascii') since a well formatted URL cannot contain anything else than ASCII.

Benoss commented 9 years ago

Good point, will try to change this tomorrow, or you can post a create a Pull request if you want to

Benoss commented 9 years ago

1.0.3 should fix this

pquentin commented 9 years ago

@Benoss Thank you for the fixes!