hive - pyhive连接错误: thrift. Transport.TTransport.TTransportException:TSocket读取0字节

标签 hive hortonworks-data-platform pyhive

我正在尝试获取位于 hive (hortonworks) 中的一个表,以收集一些 Twitter 数据以在机器学习项目上实现,使用 pyhive,因为 python3.6 不支持 pyhs2。

这是我的代码:

from pyhive import hive
conn = hive.Connection(host='192.168.1.11', port=10000, auth='NOSASL')
import pandas as pd
import sys
df = pd.read_sql("SELECT * FROM my_table", conn)
print(sys.getsizeof(df))
df.head()

出现此错误:

Traceback (most recent call last):
File "C:\Users\PWST112\Desktop\import.py", line 44, in <module>
conn = hive.Connection(host='192.168.1.11', port=10000, auth='NOSASL')
File "C:\Users\PWST112\AppData\Local\Programs\Python\Python36\lib\site-    packages\pyhive\hive.py", line 164, in __init__
response = self._client.OpenSession(open_session_req)
File "C:\Users\PWST112\AppData\Local\Programs\Python\Python36\lib\site- packages\TCLIService\TCLIService.py", line 187, in OpenSession
return self.recv_OpenSession()
File "C:\Users\PWST112\AppData\Local\Programs\Python\Python36\lib\site-packages\TCLIService\TCLIService.py", line 199, in recv_OpenSession
(fname, mtype, rseqid) = iprot.readMessageBegin()
File "C:\Users\PWST112\AppData\Local\Programs\Python\Python36\lib\site-packages\thrift\protocol\TBinaryProtocol.py", line 148, in readMessageBegin
name = self.trans.readAll(sz)
File "C:\Users\PWST112\AppData\Local\Programs\Python\Python36\lib\site-packages\thrift\transport\TTransport.py", line 60, in readAll
chunk = self.read(sz - have)
File "C:\Users\PWST112\AppData\Local\Programs\Python\Python36\lib\site-packages\thrift\transport\TTransport.py", line 161, in read
self.__rbuf = BufferIO(self.__trans.read(max(sz, self.__rbuf_size)))
File "C:\Users\PWST112\AppData\Local\Programs\Python\Python36\lib\site-packages\thrift\transport\TSocket.py", line 132, in read
message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
[Finished in 0.3s]

这是点列表:

beautifulsoup4 (4.6.0)
bleach (2.0.0)
colorama (0.3.9)
cycler (0.10.0)
decorator (4.0.11)
entrypoints (0.2.3)
ez-setup (0.9)
future (0.16.0)
html5lib (0.999999999)
impala (0.2)
ipykernel (4.6.1)
ipython (6.1.0)
ipython-genutils (0.2.0)
ipywidgets (6.0.0)
jedi (0.10.2)
Jinja2 (2.9.6)
jsonschema (2.6.0)
jupyter (1.0.0)
jupyter-client (5.1.0)
jupyter-console (5.1.0)
jupyter-core (4.3.0)
konlpy (0.4.4)
MarkupSafe (1.0)
matplotlib (2.0.2)
mistune (0.7.4)
nbconvert (5.2.1)
nbformat (4.3.0)
nltk (3.2.4)
notebook (5.0.0)
numpy (1.13.1+mkl)
pandas (0.20.3)
pandocfilters (1.4.1)
pickleshare (0.7.4)
pip (9.0.1)
prompt-toolkit (1.0.14)
pure-sasl (0.4.0)
Pygments (2.2.0)
PyHive (0.5.0)
pyhs2 (0.6.0)
pyparsing (2.2.0)
python-dateutil (2.6.0)
pytz (2017.2)
pyzmq (16.0.2)
qtconsole (4.3.0)
sasl (0.2.1)
scikit-learn (0.18.2)
scipy (0.19.1)
setuptools (28.8.0)
simplegeneric (0.8.1)
six (1.10.0)
testpath (0.3.1)
thrift (0.10.0)
thrift-sasl (0.3.0)
tornado (4.5.1)
traitlets (4.3.2)
wcwidth (0.1.7)
webencodings (0.5.1)
wheel (0.30.0)
widgetsnbextension (2.0.0)

有人可以帮忙吗? 我使用的是 Windows 10。

提前非常感谢。

最佳答案

我不确定 Hortonworks 工具,但总的来说,Cloudera 连接似乎与 Thrift 和 Sasl 存在问题。

this issue 的帮助下,我能够获得 SqlAlchemy 连接(使用 Thrift)推送和拉取数据。在 Cloudera 的 Impyla 模块上 - 它不是 PyHive,但 Thrift Tsocket 连接似乎也是导致代码错误的原因。您可以尝试对模块进行版本锁定;缺点是它需要 Python 2.7。

如果您想测试版本锁定,这就是让我建立有效的 Thrift 连接的原因:

pip install thrift==0.9.3
pip install thrift_sasl==0.2.1
pip uninstall sasl && pip install pure-sasl

希望这有帮助!

关于hive - pyhive连接错误: thrift. Transport.TTransport.TTransportException:TSocket读取0字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47334686/

相关文章:

python - 使用 `PyHive`使用表格名称开头的数字访问Hive表格会出现错误

hadoop - 通过 Oozie HDP 2.1 的作业不创建 job.splitmetainfo

hadoop - PyHive忽略Hive配置

python - 在哪里可以找到 hive url、用户名和密码?

hadoop - 如何删除和更新 Hive 中的记录

hadoop - Hadoop 和 Hive 的基本知识

hadoop - oozie hive hadoop 作业

hadoop - Spring XD流仅创建空的.tmp文件

hadoop - HortonWorks Hadoop 沙箱和 Tableau