我对cqlsh有编码问题。
当我尝试使用CQLSH命令插入带有特殊字符的文本数据时:
cqlsh localhost -k my_keyspace -f /home/me/workspace/scripts/test.cql
(包含以下行的test.cql):
INSERT INTO table_content (tableId, title, content) VALUES ('record1', 'Mon titre', 'Mon contenu avec un accent évidemment');
我收到以下错误:
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)
我的文件以UTF-8编码。 知道如何为cqlsh命令行强制使用UTF-8编码吗?我使用以下版本(我没有选择):[cqlsh 5.0.1 |卡桑德拉2.1.8 | CQL规范3.2.0 |原生协议v3]
答案 0 :(得分:3)
cql 5.0.1中存在问题,现在处于已解决状态。 如果您无法升级,则提及以下解决方案:
通过更改cqlsh.py
的第1135行来纠正此问题readline.add_history(new_hist) - &gt; readline.add_history(new_hist.encode( 'UTF8'))