python
python hbase 报错by-凯发ag旗舰厅登录网址下载
hbase 版本: 0.98.6
thrift 版本: 0.9.0
使用 thrift client with python 连接 hbase 报错:
1 traceback (most recent call last):2 file "d:\workspace\python\py\helloworld.py", line 27, in
3 tables =client.gettablenames()4 file "e:\mazhongsoft\python\lib\hbase\hbase.py", line 788, ingettablenames5 returnself.recv_gettablenames()6 file "e:\mazhongsoft\python\lib\hbase\hbase.py", line 798, inrecv_gettablenames7 (fname, mtype, rseqid) =self._iprot.readmessagebegin()8 file "e:\mazhongsoft\python\lib\thrift\protocol\tbinaryprotocol.py", line 126, inreadmessagebegin9 sz =self.readi32()10 file "e:\mazhongsoft\python\lib\thrift\protocol\tbinaryprotocol.py", line 203, inreadi3211 buff = self.trans.readall(4)12 file "e:\mazhongsoft\python\lib\thrift\transport\ttransport.py", line 58, inreadall13 chunk = self.read(sz-have)14 file "e:\mazhongsoft\python\lib\thrift\transport\ttransport.py", line 155, inread15 self.__rbuf = stringio(self.__trans.read(max(sz, self.default_buffer)))16 file "e:\mazhongsoft\python\lib\thrift\transport\tsocket.py", line 94, inread17 raise ttransportexception(‘tsocket read 0 bytes‘)18 thrift.transport.ttransport.ttransportexception: none
查找原因,过程如下:
1) 客户端代码
1transport =ttransport.tbufferedtransport(tsocket(‘192.168.0.10‘, 9090))2 protocol =tbinaryprotocol.tbinaryprotocol(transport)3 client =hbase.client(protocol)4 transport.open()
2) hbase-site.xml 配置如下
1
2 hbase.regionserver.thrift.framed
3 true
4
5
6 hbase.regionserver.thrift.compact
7 true
8
3) thrift server日志如下:(/var/log/hbase/hbase-hbase-thrift-.log)
1 wed jan 14 14:54:43 cst 2015 starting thrift on
2 core file size (blocks, -c) 03 data seg size (kbytes, -d) unlimited4 scheduling priority (-e) 05 file size (blocks, -f) unlimited6 pending signals (-i) 191956
7 max locked memory (kbytes, -l) unlimited8 max memory size (kbytes, -m) unlimited9 open files (-n) 32768
10 pipe size (512 bytes, -p) 8
11 posix message queues (bytes, -q) 819200
12 real-time priority (-r) 013 stack size (kbytes, -s) 10240
14 cpu time (seconds, -t) unlimited15 max user processes (-u) 1024
16 virtual memory (kbytes, -v) unlimited17 file locks (-x) unlimited18 info [main] util.versioninfo: hbase 0.98.6-cdh5.3.0
19 info [main] util.versioninfo: subversion file:///data/jenkins/workspace/generic-package-rhel64-6-0/topdir/build/hbase-0.98.6-cdh5.3.0 -r unknown20 info [main] util.versioninfo: compiled by jenkins on tue dec 16 19:13:29 pst 2014
21 info [main] thrift.thriftserverrunner: using default thrift server type22 info [main] thrift.thriftserverrunner: using thrift server type threadpool23 info [main] impl.metricsconfig: loaded properties from hadoop-metrics2-hbase.properties24 info [main] impl.metricssystemimpl: scheduled snapshot period at 10second(s).25 info [main] impl.metricssystemimpl: hbase metrics system started26 info [main] mortbay.log: logging to org.slf4j.impl.log4jloggeradapter(org.mortbay.log) via org.mortbay.log.slf4jlog27 info [main] http.httpserver: added global filter ‘safety‘ (class=org.apache.hadoop.http.httpserver$quotinginputfilter)
28 info [main] http.httpserver: added filter static_user_filter (class=org.apache.hadoop.http.lib.staticuserwebfilter$staticuserfilter) to context thrift29info [main] http.httpserver: added filter static_user_filter (class=org.apache.hadoop.http.lib.staticuserwebfilter$staticuserfilter) to context static30 info [main] http.httpserver: jetty bound to port 9095
31 info [main] mortbay.log: jetty-6.1.26.cloudera.4
32 info [main] mortbay.log: started [email protected]:9095
33 debug [main] thrift.thriftserverrunner: using compact protocol34 debug [main] thrift.thriftserverrunner: using framed transport35 info [main] thrift.thriftserverrunner: starting tboundedthreadpoolserver on /0.0.0.0:9090; min worker threads=16, max worker threads=1000, max queued requests=1000
由以上红色文字部分可知,是因为thrift 的server端和client端的协议不匹配造成的。
凯发ag旗舰厅登录网址下载的解决方案有如下两个:
方案一:修改hbase-site.xml,禁用tframedtransport和tcompactprotocol功能,即:
1
2 hbase.regionserver.thrift.framed
3 false
4
5
6 hbase.regionserver.thrift.compact
7 false
8
重启thrift 服务器: service hbase-thrift restart
方案二:修改客户端代码
1 transport = tframedtransport(tsocket(‘192.168.0.10‘, 9090))2 protocol =tcompactprotocol.tcompactprotocol(transport)3 client =hbase.client(protocol)4 transport.open()
如果报错未找到tframedtransport和tcompactprotocol,请查看/usr/lib/python2.6/site-packages/thrift目录下有没有protocol/tcompactprotocol.py文件,检查transport/ttransport.py文件中有没有类tframedtransport。如果没有,可以在thrift凯发ag旗舰厅登录网址下载官网下载源码包 thrift-0.9.2.tar.gz,用其中的lib/py/src/覆盖/usr/lib/python2.6/site-packages/thrift/目录即可。
原文:http://www.cnblogs.com/zhangningbo/p/4303422.html
总结
以上是凯发ag旗舰厅登录网址下载为你收集整理的python hbase 报错by_【hbase】使用thrift with python 访问hbase的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。
- 上一篇: python网络爬虫入门小程序_pyth
- 下一篇: python字典值的和计算_第一章pyt