Skip to content

fix UnicodeDecodeError when printing tuples with binary data #93

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

Merged
merged 1 commit into from
Aug 30, 2017

Conversation

zimnukhov
Copy link
Contributor

The following script fails when trying to print tuple with raw byte field that is not valid utf8:

import tarantool
conn = tarantool.connect('localhost', 31539, encoding=None)
conn.replace('test_space', ('foo', b'\xff'))
print(conn.select('test_space', 'foo'))

traceback:

  File "/Users/zimnukhov/tmp/tarantool-python/tarantool/response.py", line 232, in __str__
    output.extend(("- ", json.dumps(tpl), "\n"))
  File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte

I suggest using repr instead of json to serialize tuples. The above script will print:

- ['foo', '\xff']

@bigbes bigbes merged commit 9e15f7b into tarantool:master Aug 30, 2017
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

Successfully merging this pull request may close these issues.

2 participants