3
votes

i have encoding issue with cqlsh.

When i try to insert text data with special characters using CQLSH command:

cqlsh localhost -k my_keyspace -f /home/me/workspace/scripts/test.cql

(test.cql containing the following line):

INSERT INTO table_content (tableId, title, content) VALUES ('record1', 'Mon titre', 'Mon contenu avec un accent évidemment');

i get the following error :

Traceback (most recent call last):
File "/opt/applications/apache-cassandra-2.1.8/bin/cqlsh", line 2459, in <module>
main(*read_options(sys.argv[1:], os.environ))
File "/opt/applications/apache-cassandra-2.1.8/bin/cqlsh", line 2451, in main
shell.cmdloop()
  File "/opt/applications/apache-cassandra-2.1.8/bin/cqlsh", line 940, in cmdloop
    line = self.get_input_line(self.prompt)
  File "/opt/applications/apache-cassandra-2.1.8/bin/cqlsh", line 909, in get_input_line
    self.lastcmd = self.stdin.readline()
  File "/usr/lib/python2.7/codecs.py", line 672, in readline
    return self.reader.readline(size)
  File "/usr/lib/python2.7/codecs.py", line 527, in readline
    data = self.read(readsize, firstline=True)
  File "/usr/lib/python2.7/codecs.py", line 474, in read
    newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 26: ordinal not in range(128)

My file is encoded in UTF-8 though. Any idea how to force UTF-8 encoding for cqlsh command line ? I use the following version (and i don't have the choice): [cqlsh 5.0.1 | Cassandra 2.1.8 | CQL spec 3.2.0 | Native protocol v3]

1

1 Answers

3
votes

There was issue in cql 5.0.1 which is in resolved state now. If you can't upgrade then following solution is mentioned:

The issue was corrected by changing line 1135 of cqlsh.py

readline.add_history(new_hist) -> readline.add_history(new_hist.encode('utf8'))

More Details