PyHive icon indicating copy to clipboard operation
PyHive copied to clipboard

Can't connect to unsecured hive. SASL error: TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2

Open SaucePan1 opened this issue 7 years ago • 19 comments

This is the code

from pyhive import hive
conn = hive.Connection(host='host_name_with_auth_none' , port=10000, auth='NONE' )
cursor = conn.cursor()
cursor.execute("SHOW TABLES")
for table in cursor.fetchall():
    print table

I get the following error:


TTransportException Traceback (most recent call last) in () 1 from pyhive import hive ----> 2 conn = hive.Connection(host='host_',port=10000, auth='NONE' ) 3 4 cursor = conn.cursor() 5 cursor.execute("SHOW TABLES")

C:\Users\u19m41\AppData\Local\Continuum\Anaconda2\lib\site-packages\pyhive-0.5.0-py2.7.egg\pyhive\hive.pyc in init(self, host, port, username, database, auth, configuration, kerberos_service_name, password, thrift_transport) 157 158 try: --> 159 self._transport.open() 160 open_session_req = ttypes.TOpenSessionReq( 161 client_protocol=protocol_version,

C:\Users\u19m41\AppData\Local\Continuum\Anaconda2\lib\site-packages\thrift_sasl-0.2.1-py2.7.egg\thrift_sasl_init_.pyc in open(self) 70 if not ret: 71 raise TTransportException(type=TTransportException.NOT_OPEN, ---> 72 message=("Could not start SASL: %s" % self.sasl.getError())) 73 74 # Send initial response

TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2

Any idea on why this is happening?

SaucePan1 avatar Sep 21 '17 15:09 SaucePan1

Can you confirm that your HS2's hive.server2.authentication matches what your passing to PyHive's auth parameter?

This is known to work in the Travis build setup, so if there's nothing obvious, you can troubleshoot by comparing your configs with what .travis.yml sets up.

jingw avatar Sep 22 '17 03:09 jingw

i encontered the same quetion,and i sure the configuration is mated, but the error is always there.

how can i solve it?

plz help me, thanks.

hive.server2.authentication NONE

cursor = hive.Connection(host='114.55.41.85').cursor()

thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'

duniang818 avatar Oct 11 '17 07:10 duniang818

@SaucePan1

duniang818 avatar Oct 11 '17 07:10 duniang818

@jingw Yes I already confirmed this.

I solved the issue using impyla (instead of pyhive), and getting PURE-SASL instead of SASL. This is the issue I opened on impyla: https://github.com/cloudera/impyla/issues/267

SaucePan1 avatar Oct 11 '17 10:10 SaucePan1

I don't know then, sorry. Glad to hear you solved your issue.

jingw avatar Oct 11 '17 21:10 jingw

I have solved the same issue installing the package libsasl2-modules in Ubuntu.

requirements.txt

PyHive==0.5.0
sasl==0.2.1
thrift==0.10.0
thrift-sasl==0.3.0

Dockerfile

FROM python:3.6

RUN apt-get update && apt-get install -y libsasl2-modules libsasl2-dev

WORKDIR /code
ADD requirements.txt .
RUN pip install -r requirements.txt

servomac avatar Nov 03 '17 13:11 servomac

@servomac Thanks a lot.

rajnishgarg avatar Mar 22 '18 08:03 rajnishgarg

@SaucePan1 I had similar issue, I followed most of the steps suggested here in this thread, i.e set authentication to NONE, had latest version of all the packages (sasl, thrift, pyhive) but still did not work. Seems like only piece missing for me was plain kerberos plugin, so i did - yum install cyrus-sasl-plain

this was helpful

dhananjaymehta avatar Mar 24 '18 22:03 dhananjaymehta

Hi Dhananjay

       We are trying to connect hive tables from python ,while connecting facing issues.We are sending our full details please help on this.

we installed python version 2.7.15 and anaconda version 2.7.14 We installed below packages

pip install sasl pip install thrift pip install thrift-sasl pip install PyHive

we written the below code to connect hive tables from python script

from pyhive import hive conn = hive.Connection(host="172.16.17.196", port=10000, username="mapr", database="default") cursor = conn.cursor() cursor.execute("SHOW DATABASES") for result in cursor.fetchall(): use_result(result)

We are getting below error

==========================

Traceback (most recent call last): File "", line 1, in File "C:\Users\mapr\Anaconda2\lib\site-packages\pyhive\hive.py", line 64, in connect return Connection(*args, **kwargs) File "C:\Users\mapr\Anaconda2\lib\site-packages\pyhive\hive.py", line 162, in init self.transport.open() File "C:\Users\mapr\Anaconda2\lib\site-packages\thrift_sasl_init.py", line 79, in open message=("Could not start SASL: %s" % self.sasl.getError())) thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2

srinu989 avatar Jun 11 '18 10:06 srinu989

@dhananjaymehta That did not worked for me. Does it require any additional configuration?

ufukomer avatar Jun 21 '18 11:06 ufukomer

Hi Dhananjay

       We are trying to connect hive tables from python ,while connecting facing issues.We are sending our full details please help on this.

we installed python version 2.7.15 and anaconda version 2.7.14 We installed below packages

pip install sasl pip install thrift pip install thrift-sasl pip install PyHive

we written the below code to connect hive tables from python script

from pyhive import hive conn = hive.Connection(host="172.16.17.196", port=10000, username="mapr", database="default") cursor = conn.cursor() cursor.execute("SHOW DATABASES") for result in cursor.fetchall(): use_result(result)

We are getting below error

==========================

Traceback (most recent call last): File "", line 1, in File "C:\Users\mapr\Anaconda2\lib\site-packages\pyhive\hive.py", line 64, in connect return Connection(*args, **kwargs) File "C:\Users\mapr\Anaconda2\lib\site-packages\pyhive\hive.py", line 162, in init self.transport.open() File "C:\Users\mapr\Anaconda2\lib\site-packages\thrift_sasl__init_.py", line 79, in open message=("Could not start SASL: %s" % self.sasl.getError())) thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2

I'm not sure if it was the exact same error but I got a similar one and solved it by installing SASL manually through this:

Download unofficial from: https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl (via https://stackoverflow.com/questions/26505882/unable-to-install-sasl-0-1-3-python-package-on-windows-machine/35985464)

tsktsktsk123 avatar Feb 14 '19 16:02 tsktsktsk123

This may be sasl's problem, I use https://blog.csdn.net/wenjun_xiao/article/details/104458940 to solve this problem

wenjunxiao avatar Feb 25 '20 12:02 wenjunxiao

Thanks @wenjunxiao

sasl package needs to find a plugin folder named "sasl2" which possibly located in site-packages/sasl or Library/bin and needs to be defined in windows registry string SOFTWARE\Carnegie Mellon\Project Cyrus\SASL Library\SearchPath another option is to copy sasl2 into C:\CMU\bin\

refer to https://github.com/cyrusimap/cyrus-sasl/blob/master/lib/common.c#L2472

cdarlint avatar May 11 '20 06:05 cdarlint

I want solution!!

wslee4859 avatar Jul 23 '20 06:07 wslee4859

I don't understand these registry thing, is this a must to be done manually or it's just something did not go well when packaging?

For other that need a solution, creating a folder locally in C:/CMU/bin did work, it seems crazy to me.

noklam avatar Sep 15 '20 16:09 noklam

The following works for me

set authentication to nosasl in your hive-site.xml

and with hypive

conn = hive.Connection(host="hive-server", port=10000, auth='NOSASL', database='default')

jessequinn avatar Nov 12 '20 11:11 jessequinn

I was able to install sasl after follow these steps:

https://dwgeek.com/guide-connecting-hiveserver2-using-python-pyhive.html/

ggasque-abi avatar Jan 20 '23 15:01 ggasque-abi

On Windows, I fixed this error by

  1. Find the sasl2 folder. The simplest way is to go to your Python folder (or Python env folder if you use env) and search for "sasl" using the Windows search tool. I'm using anaconda env and it's at something like "C:\Users\quang.conda\envs\envsName\Library\bin\sasl2"
  2. Create a folder like C:/CMU/bin and copy the whole sasl2 folder into it. Something like C:/CMU/bin/sasl2

quangbilly79 avatar May 09 '23 08:05 quangbilly79

sudo apt-get install sasl2-bin libsasl2-2 libsasl2-dev libsasl2-modules In my case above command solved the issue. It was a dependency issue.

shambhu1998 avatar Jun 29 '23 12:06 shambhu1998