为什么cqlsh在LookupError中失败:未知编码



我刚刚在Mac OS X 10.9.4:上使用brew安装了Cassandra

➜  ~  brew info cassandra
cassandra: stable 2.1.0
http://cassandra.apache.org
/usr/local/Cellar/cassandra/2.0.9 (3466 files, 79M) *
  Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/cassandra.rb
==> Caveats
If you plan to use the CQL shell (cqlsh), you will need the Python CQL library
installed. Since Homebrew prefers using pip for Python packages, you can
install that using:
  pip install cql
To have launchd start cassandra at login:
    ln -sfv /usr/local/opt/cassandra/*.plist ~/Library/LaunchAgents
Then to load cassandra now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.cassandra.plist
➜  ~  uname -a
Darwin xxx 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun  3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

如上面的信息消息中所建议的,要安装cql,我先执行sudo easy_install pip,然后执行pip install cql

安装软件后,在执行cqlsh时,我面临错误:

➜  ~  cqlsh
Traceback (most recent call last):
  File "/usr/local/bin/cqlsh", line 2084, in <module>
    main(*read_options(sys.argv[1:], os.environ))
  File "/usr/local/bin/cqlsh", line 2067, in main
    single_statement=options.execute)
  File "/usr/local/bin/cqlsh", line 509, in __init__
    self.output_codec = codecs.lookup(encoding)
LookupError: unknown encoding:

我该怎么修?

经过一些谷歌搜索和调试,发现对locale.getpreferredencoding()的调用需要正确的LC_ALL,如22.2中所述。locale--国际化服务:

为了保持与其他平台的兼容性,不仅LANG变量进行了测试,但以envvars形式给出的变量列表参数将使用第一个被定义的。envvars默认为GNU gettext中使用的搜索路径;它必须始终包含变量名LANG。GNU gettext搜索路径包含"LANGUAGE"、"LC_ALL"、"LCO_CTYPE"one_answers"LANG",按顺序排列。

在我的系统上,LC_ALL设置为pl_PL:

➜  ~  echo $LC_ALL
pl_PL

在将LC_ALL更改为plpl_pl.utf-8之后,Cassandra shell cqlsh开始正常运行:

➜  ~  export LC_ALL=pl_pl.utf-8
➜  ~  cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.9 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh>

请参阅OSX-Lion上的Problem start cqlsh线程,以获取用于检查您的区域设置的示例Python应用程序:

python -c 'import locale, codecs; encoding = locale.getpreferredencoding(); print encoding; print codecs.lookup(encoding)'

一旦它运行良好,就可以认为问题已经解决了。

最新更新