elasticsearch-py
elasticsearch-py copied to clipboard
Py2 - Error when indexing a payload with non ascii chars while passing an opaque-id
Elasticsearch version (bin/elasticsearch --version): 7
elasticsearch-py version (elasticsearch.__versionstr__): 7.9 / 7.8 / 7.7
Description of the problem including expected versus actual behavior:
When trying to send a request containing an opaque-id in Py2, the x-opaque-id headers is added as a unicode string here: https://github.com/elastic/elasticsearch-py/blob/7.9/elasticsearch/client/utils.py#L140 due to this: https://github.com/elastic/elasticsearch-py/blob/7.9/elasticsearch/client/utils.py#L18
If the request payload contains a non-ascii character, the request will fail - httplib::HTTPConnection._send_output will try to concatenate a unicode and a (utf-8) encoded string and will fail with a UnicodeDecodeError.
I believe replacing https://github.com/elastic/elasticsearch-py/blob/7.9/elasticsearch/client/utils.py#L140
with:
headers[str("x-opaque-id")] = kwargs.pop("opaque_id")
should solve this issue
Steps to reproduce: using the Py2 client, execute an index request with payload containing a non-ascii character while supplying an opaque_id parameter.