Python Impyla fails after Kerberos install
Question: I'm on a W7 machine, where I use Python (Anaconda distribution) to connect to
Impala in our Hadoop cluster using the Impyla package. My company has recently
added Kerberos and that ended up breaking what I had in place.

**before Kerberos:**

    
    
    from impala.dbapi import connect
    conn = connect( host='localhost', port=21050)
    cur = conn.cursor()
    
    cur.execute('SHOW TABLES')
    cur.fetchall()
    

**after Kerberos**

    
    
    from impala.dbapi import connect
    conn = connect( host='localhost', port=21050, use_kerberos=True,
                   kerberos_service_name='impala/myservername')
    
    Traceback (most recent call last):
    
      File "<ipython-input-13-068c7348729f>", line 2, in <module>
        kerberos_service_name='impala/myservername')
    
      File "C:\Users\x\AppData\Local\Continuum\Anaconda\lib\site-packages\impala\dbapi\__init__.py", line 47, in connect
        ldap_password, use_kerberos, kerberos_service_name)
    
      File "C:\Users\x\AppData\Local\Continuum\Anaconda\lib\site-packages\impala\_rpc\hiveserver2.py", line 193, in connect_to_impala
        use_kerberos, kerberos_service_name)
    
      File "C:\Users\x\AppData\Local\Continuum\Anaconda\lib\site-packages\impala\_rpc\hiveserver2.py", line 166, in _get_transport
        import sasl
    
    ImportError: No module named sasl
    

I tried installing sasl from CMD:

    
    
    >easy_install sasl
    Searching for sasl
    Reading https://pypi.python.org/simple/sasl/
    Best match: sasl 0.1.3
    Downloading https://pypi.python.org/packages/source/s/sasl/sasl-0.1.3.tar.gz#md5
    =6db4ca3d4fb699cf126a6e6f2f516d8f
    Processing sasl-0.1.3.tar.gz
    Writing c:\users\x\appdata\local\temp\easy_install-zfqesn\sasl-0.1.3\setup
    .cfg
    Running sasl-0.1.3\setup.py -q bdist_egg --dist-dir c:\users\x\appdata\loc
    al\temp\easy_install-zfqesn\sasl-0.1.3\egg-dist-tmp-cl0non
    sasl/saslwrapper.cpp:21:23: fatal error: sasl/sasl.h: No such file or directory
    compilation terminated.
    error: Setup script exited with error: command 'C:\\Users\\x\\AppData\\Loc
    al\\Continuum\\Anaconda\\Scripts\\gcc.bat' failed with exit status 1
    


Answer: I see you are running Windows. Are you running cygwin or some other python?

Have you tried:

  1. If using Cygwin, have you tried installing libsasl2-devel ?

  2. installing python-sasl from the GIT repository as Cloudera seems to do as part of their [jenkins environment](https://github.com/cloudera/impyla/blob/86e1a9f916785ccc77700de4327ecf77e4820fbd/jenkins/run-dbapi.sh#L90)?

pip install git+<https://github.com/laserson/python-sasl.git@cython>

Should do the magic.

By the way, the code you are using has been deprecated (as per the current
GitHub master).

Use

    
    
    from impala.dbapi import connect
    conn = connect( host='localhost', port=21050, auth_mechanism='GSSAPI',
                   kerberos_service_name='impala')
    

