HBase 版本: 0.98.6

thrift   版本: 0.9.0

使用 thrift client with python 连接 HBase 报错:

 Traceback (most recent call last):
File "D:\workspace\Python\py\helloworld.py", line 27, in <module>
tables = client.getTableNames()
File "E:\mazhongsoft\python\lib\hbase\Hbase.py", line 788, in getTableNames
return self.recv_getTableNames()
File "E:\mazhongsoft\python\lib\hbase\Hbase.py", line 798, in recv_getTableNames
(fname, mtype, rseqid) = self._iprot.readMessageBegin()
File "E:\mazhongsoft\python\lib\thrift\protocol\TBinaryProtocol.py", line 126, in readMessageBegin
sz = self.readI32()
File "E:\mazhongsoft\python\lib\thrift\protocol\TBinaryProtocol.py", line 203, in readI32
buff = self.trans.readAll(4)
File "E:\mazhongsoft\python\lib\thrift\transport\TTransport.py", line 58, in readAll
chunk = self.read(sz-have)
File "E:\mazhongsoft\python\lib\thrift\transport\TTransport.py", line 155, in read
self.__rbuf = StringIO(self.__trans.read(max(sz, self.DEFAULT_BUFFER)))
File "E:\mazhongsoft\python\lib\thrift\transport\TSocket.py", line 94, in read
raise TTransportException('TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: None

查找原因,过程如下:
1) 客户端代码

1 transport = TTransport.TBufferedTransport(TSocket('192.168.0.10', 9090))
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()

2) hbase-site.xml 配置如下

   <property>
<name>hbase.regionserver.thrift.framed</name>
<value>true</value>
</property>
<property>
<name>hbase.regionserver.thrift.compact</name>
<value>true</value>
</property>

3) thrift server日志如下:(/var/log/hbase/hbase-hbase-thrift-<hostname>.log)

 Wed Jan 14 14:54:43 CST 2015 Starting thrift on <hostname>
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 191956
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 32768
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 1024
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
INFO [main] util.VersionInfo: HBase 0.98.6-cdh5.3.0
INFO [main] util.VersionInfo: Subversion file:///data/jenkins/workspace/generic-package-rhel64-6-0/topdir/BUILD/hbase-0.98.6-cdh5.3.0 -r Unknown
INFO [main] util.VersionInfo: Compiled by jenkins on Tue Dec 16 19:13:29 PST 2014
INFO [main] thrift.ThriftServerRunner: Using default thrift server type
INFO [main] thrift.ThriftServerRunner: Using thrift server type threadpool
INFO [main] impl.MetricsConfig: loaded properties from hadoop-metrics2-hbase.properties
INFO [main] impl.MetricsSystemImpl: Scheduled snapshot period at 10 second(s).
INFO [main] impl.MetricsSystemImpl: HBase metrics system started
INFO [main] mortbay.log: Logging to org.slf4j.impl.Log4jLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
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 thrift
INFO [main] http.HttpServer: Added filter static_user_filter (class=org.apache.hadoop.http.lib.StaticUserWebFilter$StaticUserFilter) to context static
INFO [main] http.HttpServer: Jetty bound to port 9095
INFO [main] mortbay.log: jetty-6.1.26.cloudera.4
INFO [main] mortbay.log: Started HttpServer$SelectChannelConnectorWithSafeStartup@0.0.0.0:9095
DEBUG [main] thrift.ThriftServerRunner: Using compact protocol
DEBUG [main] thrift.ThriftServerRunner: Using framed transport
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端的协议不匹配造成的。

解决方案有如下两个:
方案一:修改hbase-site.xml,禁用TFramedTransport和TCompactProtocol功能,即:

   <property>
<name>hbase.regionserver.thrift.framed</name>
<value>false</value>
</property>
<property>
<name>hbase.regionserver.thrift.compact</name>
<value>false</value>
</property>

重启thrift 服务器: service hbase-thrift restart

方案二:修改客户端代码

 transport = TFramedTransport(TSocket('192.168.0.10', 9090))
protocol = TCompactProtocol.TCompactProtocol(transport)
client = Hbase.Client(protocol)
transport.open()

如果报错未找到TFramedTransport和TCompactProtocol,请查看/usr/lib/python2.6/site-packages/thrift目录下有没有protocol/TCompactProtocol.py文件,检查transport/TTransport.py文件中有没有类TFramedTransport。如果没有,可以在thrift官网下载源码包 thrift-0.9.2.tar.gz,用其中的lib/py/src/覆盖/usr/lib/python2.6/site-packages/thrift/目录即可。

【hbase】使用thrift with python 访问HBase的更多相关文章

  1. 【Hbase三】Java,python操作Hbase

    Java,python操作Hbase 操作Hbase python操作Hbase 安装Thrift之前所需准备 安装Thrift 产生针对Python的Hbase的API 启动Thrift服务 执行p ...

  2. python连接hbase

    安装HBase HBase是一个构建在HDFS上的分布式列存储系统,主要用于海量结构化数据存储.这里,我们的目标只是为Python访问HBase提供一个基本的环境,故直接下载二进制包,采用单机安装.下 ...

  3. 使用C#通过Thrift访问HBase

    前言 因为项目需要要为客户程序提供C#.Net的HBase访问接口,而HBase并没有提供原生的.Net客户端接口,可以通过启动HBase的Thrift服务来提供多语言支持. Thrift介绍 环境 ...

  4. 使用C#和Thrift来访问Hbase实例

    今天试着用C#和Thrift来访问Hbase,主要参考了博客园上的这篇文章.查了Thrift,Hbase的资料,结合博客园的这篇文章,终于搞好了.期间经历了不少弯路,下面我尽量详细的记录下来,免得大家 ...

  5. ambari安装集群下python连接hbase之安装thrift

    简介: python连接hbase是需要通过thrift连进行连接的,ambari安装的服务中貌似没有自带安装hbase的thrift,我是看配置hbase的配置名称里面没有thrift,cdh版本的 ...

  6. Hbase理论&&hbase shell&&python操作hbase&&python通过mapreduce操作hbase

    一.Hbase搭建: 二.理论知识介绍: 1Hbase介绍: Hbase是分布式.面向列的开源数据库(其实准确的说是面向列族).HDFS为Hbase提供可靠的底层数据存储服务,MapReduce为Hb ...

  7. python 操作 hbase

    python 是万能的,当然也可以通过api去操作big database 的hbase了,python是通过thrift去访问操作hbase 以下是在centos7 上安装操作,前提是hbase已经 ...

  8. HBase(一): c#访问hbase组件开发

    HDP2.4安装系列介绍了通过ambari创建hbase集群的过程,但工作中一直采用.net的技术路线,如何去访问基于Java搞的Hbase呢? Hbase提供基于Java的本地API访问,同时扩展了 ...

  9. Hadoop Hive与Hbase整合+thrift

    Hadoop Hive与Hbase整合+thrift 1.  简介 Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供完整的sql查询功能,可以将sql语句 ...

随机推荐

  1. 素数筛法--SPOJ Problem 2 Prime Generator

    质数(prime number)又称素数,除了1和它本身外,不能整除以其他自然数,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.最小的质数是2. 要判断一个整数N是不是质数很简单, ...

  2. opencv求取RGB分量

    需要注意的是下面r,b,g的类型和顺序 须用IPL_DEPTH_8U类型创建图像且[0][1][2]分量分别是b,g,r. 另外多谢郑乾师兄帮我发现了IPL_DEPTH_8U问题 uchar r,b, ...

  3. 怎么在eclipse里调试WebDriver的源代码

    当你看完WebDriver的工作原理这篇博客以后,是不是也跃跃欲试想印证文章里的理论是不是正确,想自己也看下webdriver的源代码,并且调试下,通过代码来更深入的了解WebDriver的工作原理. ...

  4. mysql 插入汉字 异常 Incorrect string value: '\xE8\xA7\x84\xE5\x88\x99' for column 'name'

    今天使用mysql出现 Incorrect string value: '\xE8\xA7\x84\xE5\x88\x99' for column 'name' 异常 通过查找问题,发现是字段编码不支 ...

  5. Android新版本SDK打开旧版本项目报错解决

    1.Description Resource Path Location Type Unable to resolve target 'android-19 解决:打开project.properti ...

  6. Collection_Compare

    冒泡 package com.bjsxt.sort.bubble; import java.util.Arrays; public class BubbleSort1 { /** * @param a ...

  7. Support Library官方教程(1)概述

    Support Library The Android Support Library package is a set of code libraries that provide backward ...

  8. GIT使用教程与基本原理

    转自:http://blog.csdn.net/wengpingbo/article/details/8985132 说明:该教程全部图片都来自于<pro git>.以下所有的操作,除非特 ...

  9. bzoj1832: [AHOI2008]聚会

    写过的题... #include<cstdio> #include<cstring> #include<iostream> #include<algorith ...

  10. 转:MVC 下导航超链接本页面高亮的一种解决方案

    前言 导航高亮一直是一个让大家头疼的问题. 纯 Javascript 的话可以判断当前页面的地址和链接地址是否有关系. 这样的弊端就是自由度太低,MVC 下会出一定的问题 (MVC 下有默认的 Con ...