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

handle unicode encoding errors #6

Closed
wants to merge 1 commit into from
Closed

Conversation

bmschwa
Copy link

@bmschwa bmschwa commented Aug 26, 2016

On line 368, if we fail to convert a unicode string - replace the unicode chars

@foutaise
Copy link
Owner

Hi Bryan,

Could you please provide an example in order to reproduce
the problem, and details about the version of python you're using please.

I'll have to improve this part of the code obviously, cause it does not handle
unicode literals under python2. I already have a fix in mind, but I'd like to have
details about your specific case.

As a reminder for myself, here goes an example that does not work under python2 right now:

$ cat test.py
# coding=utf-8

import texttable

table = texttable.Texttable()
table.add_rows([
    ["Name", "age"],
    [u'Éric', 12]])
print(table.draw())

Gives the following error under python2:

$ python2 test.py
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    [u'Éric', 12]])
  File "/usr/home/jef/git/src/github.com/foutaise/texttable/texttable.py", line 331, in add_rows
    self.add_row(row)
  File "/usr/home/jef/git/src/github.com/foutaise/texttable/texttable.py", line 310, in add_row
    cells.append(self._str(i, x))
  File "/usr/home/jef/git/src/github.com/foutaise/texttable/texttable.py", line 369, in _str
    return str(x)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc9' in position 0: ordinal not in range(128)

Thanks.

@foutaise
Copy link
Owner

Released version 0.8.5 to fix those issues.

@foutaise foutaise closed this Sep 17, 2016
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