dropbox / PyHive

Python interface to Hive and Presto. 🐝
Other
1.67k stars 550 forks source link

thrift.transport.TTransport.TTransportException: TSocket read 0 bytes #185

Open v23Codes opened 6 years ago

v23Codes commented 6 years ago

I'm trying to connect to hive using python. I tried using both pyhive and pyhs2 but it gives the following error.

Traceback (most recent call last): File "hello.py", line 8, in database='hello') as conn: File "/usr/local/lib/python2.7/dist-packages/pyhs2/init.py", line 7, in connect return Connection(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/pyhs2/connections.py", line 47, in init res = self.client.OpenSession(TOpenSessionReq(username=user, password=password, configuration=configuration)) File "/usr/local/lib/python2.7/dist-packages/pyhs2/TCLIService/TCLIService.py", line 154, in OpenSession return self.recv_OpenSession() File "/usr/local/lib/python2.7/dist-packages/pyhs2/TCLIService/TCLIService.py", line 165, in recv_OpenSession (fname, mtype, rseqid) = self._iprot.readMessageBegin() File "build/bdist.linux-x86_64/egg/thrift/protocol/TBinaryProtocol.py", line 148, in readMessageBegin File "build/bdist.linux-x86_64/egg/thrift/transport/TTransport.py", line 60, in readAll File "build/bdist.linux-x86_64/egg/thrift/transport/TTransport.py", line 161, in read File "build/bdist.linux-x86_64/egg/thrift/transport/TSocket.py", line 132, in read thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

Nothing mentioned in forums or internet was able to help me bypass this issue. Is there a workaround for this ?

I am using oracle virtual box vm to run ubuntu 16.04

lumosleo commented 6 years ago

This looks more like an error on the hive server side of things.Have you tried restarting your hive server and also, if you are using the default derby metastore for hive have you tried removing the lock in your metastore_db folder ?? (rm ~/metastore_db/*.lck )

servomac commented 6 years ago

It seems something related with a timeout. Does anybody knows how the socket connection timeouts are defined in the server side with HiveServer2?

Sarnath commented 6 years ago

If you got that error immediately - then it is not a timeout.

I had the same problem where the python program will simply fail with this error message immediately... So, mine was not a timeout problem.

It turned out that the hiveserver2 was running with "http" as the transport mode. I changed that to "binary" and pyhive worked like a charm. Hope this helps!

Look at hive.server2.transport.mode config (am pulling from memory.. you can always goog and find out) . Change that to binary and restart HS2. Good Luck!

Before restarting - ensure that no other apps are counting on transport mode of HTTP... Or you will be bringing them all down.

SuiMingYang commented 4 years ago

@v23Codes , Has your problem solved? The same problem. I used dbeaver for test on my local env , successed , when using pyhive , it return 'TSocket read 0 bytes' after 1 minute.