Python connect to Hadoop using Hive with Kerberos authentication - python

I am trying to connect python to Hadoop using Hive using Kerberos. Tried various sources but failed in connecting
import pyhs2
conn_config = {'krb_host': 'hostname', 'krb_service': 'hive'}
pyhs2.connect(host='hostname',
port=10000,
authMechanism="KERBEROS",
password="********",
user='hostname#SCGLOBALUAT.ADUAT.SCOTIACAPITAL.COM')
Error Encountered:
authMechanism="KERBEROS") as conn:
File "build\bdist.win-amd64\egg\pyhs2\__init__.py", line 7, in connect
File "build\bdist.win-amd64\egg\pyhs2\connections.py", line 46, in __init__
File "build\bdist.win-amd64\egg\pyhs2\cloudera\thrift_sasl.py", line 66, in open
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
can please somebody help me to give clear instructions to connect python to Hadoop using Hive with Kerberos Ticket

Related

Python mariadb module does not connect to database on network

I am trying to connect to a mariadb-database on my local network. using Python.
import mariadb
cursor = mariadb.connect(host='192.168.178.77', user='someuser', password='somepass', db='temps')
Output is:
Traceback (most recent call last):
File "/Users/localuser/PycharmProjects/SQL/main.py", line 20, in <module>
cursor = mariadb.connect(host='192.168.178.77', user='someuser', password='somepass', db='temps')
File "/Users/user/.conda/envs/SQL/lib/python3.10/site-packages/mariadb/__init__.py", line 142, in connect
connection = connectionclass(*args, **kwargs)
File "/Users/localuser/.conda/envs/SQL/lib/python3.10/site-packages/mariadb/connections.py", line 86, in __init__
super().__init__(*args, **kwargs)
mariadb.OperationalError: Can't connect to server on '192.168.178.77' (60)
I can connect via Pycharms Database functionality and send SQL Statements.
I also can use DB management tools from that very host and use data without any issue.
It even works from my phone.
This code is the only place where I get an error.
OS is MacOS13.0.1
Thank You!
This happens due to a bug in MariaDB Connector/C. (Issue CONC-612).
The issue was fixed in C/C Version 3.3.3 - which is available via brew:
After
brew update
brew upgrade mariadb-connector-c
connection should work as expected.
I've got the same problem recently. Add port variable and check other. If doesn't help, try mysql-connector-python it works similar. Or install mariadb connector manually

Stuck with a MySQLdb SSL connection error in Python2.7

I have to maintain an old website built using Python2.7 that needs to continue working until we've finished creating a completely new version with more modern tools. Now this old website needs access to a remote MySQL database (connection is set up and working correctly), which so far has worked using the following:
import MySQLdb
db = MySQLdb.connect(host=Host,user=User,passwd=Pass,db=DBse)
Now the server has been upgraded from Ubuntu 18.04. to Ubuntu 20.04., and while I managed to install pip and MySQLdb for Python2.7, I now get the following error for the lines above:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2026, 'SSL connection error: unknown error number')
The SSL connection works fine in Python3 or directly from the command line.
Is there anything I can do to make this work?
Locate and add the line skip_ssl in /etc/mysql/my.cnf ( have tried this on MySQL 8.0.29 , Ubuntu 18)
This was the only thing that worked for me.
[mysqld]
skip_ssl

Not able to connect python with hive on windows machine

I have installed anaconda navigator and working in the spyder workbook.
I am getting an error like TTransport exception.
I have installed all the packages like pyhive, sasl, thrift, thrift-sasl. while connecting python to hive, I was getting this error,"Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'".
Is there any packages do I want to install?? As well I am working in windows, so kindly help me with that..
from pyhive import hive
import sasl
import thrift
import thrift_sasl
conn1 = hive.Connection(host="xxxxx", port=00000, username="yyyy")
cur2 = conn1.cursor()
Errors:
conn1 = hive.Connection(host="xxxx", port=00000, username="yyyy")
Traceback (most recent call last):
File "", line 1, in
conn1 = hive.Connection(host="xxxx", port=00000, username="yyyy")
File "C:\Users\sgpbtp02\AppData\Local\Continuum\anaconda3\lib\site-packages\pyhive\hive.py", line 192, in init
self._transport.open()
File "C:\Users\sgpbtp02\AppData\Local\Continuum\anaconda3\lib\site-packages\thrift_sasl__init__.py", line 79, in open
message=("Could not start SASL: %s" % self.sasl.getError()))
TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'

Troubleshooting pymssql connection to Azure mssql on linux cloud at pythonanywhere

I have not been able to connect to an Azure hosted MSSQL server through pymssql on pythonanywhere.
I have zero previous linux experience, so that is making it harder than it should.
I am trying this sample script provided with the instructions:
host = "123.456.789.012"
username = "yourusername"
password = "yourpassword"
database = "yourdatabasename"
conn = pymssql.connect(host, username, password, database)
cursor = conn.cursor()
But I get this error:
Traceback (most recent call last):
File "pymssql.pyx", line 635, in pymssql.connect (pymssql.c:10734)
File "_mssql.pyx", line 1902, in _mssql.connect (_mssql.c:21821)
File "_mssql.pyx", line 637, in _mssql.MSSQLConnection.__init__ (_mssql.c:6581)
File "_mssql.pyx", line 1630, in _mssql.maybe_raise_MSSQLDatabaseException (_mssql.c:17524)
_mssql.MSSQLDatabaseException: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (my_server_name.database.windows.net:1433)\n')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824)
pymssql.OperationalError: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (my_server_name.database.windows.net:1433)\n')
I figured it had to do with the TDS Version I am running, which I get to be 4.2 by running tsql -C on bash. Here is the output:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
I have tried placing a .freetds.conf file both at home/myuser/ and at home/myuser/my_virtual_env/, but that did not change any behavior. Should I have restarted the bash console or the python console? I did not think so. Here are the file contents:
[global]
tds version = 7.1
[azure]
tds version = 7.4
The other alternative would be to use pyodbc, but that would also involve configuring freetds and then some more, so it looks like there is nothing to be had there.
I should point out that I have pymssql connecting just fine to azure on my win10 machine with the following connection string:
arguments = dict(server=db_server_add, user=db_usn+"#my_server",
password=db_pswd, database=db_name, charset="utf8")
AZURE_ENGINE = create_engine('mssql+pymssql:///', connect_args=arguments)
In Python Anywhere on a free account, it does not allow access to all web addresses. Only addresses from a specific list.
"If you have a paid Python Anywhere plan"
https://help.pythonanywhere.com/pages/MSSQLServer/

Connecting standalone hbase from python

I am developing a python application with hbase as backend. I have installed hbase and its shell is working perfectly. Please note, I have not yet installed hadoop as I don't have nodes.But decided to use hbase because of impressive architecture.
Now the problem is, I am unable to connect to hbase from python either from libraries like happybase or directly using thrift. I tried this - http://binesh.in/hbase/connecting-to-a-remote-standalone-hbase/ as well, but no use. Please help me on this.
Update -
> >>> import happybase
> >>> con =happybase.Connection('localhost') Traceback (most recent call last): File "<stdin>", line 1, in <module> File
> "/usr/local/lib/python2.7/dist-packages/happybase/api.py", line 121,
> in __init__
> self.open() File "/usr/local/lib/python2.7/dist-packages/happybase/api.py", line 138,
> in open
> self.transport.open() File "build/bdist.linux-i686/egg/thrift/transport/TTransport.py", line 149,
> in open File
> "build/bdist.linux-i686/egg/thrift/transport/TSocket.py", line 99, in
> open thrift.transport.TTransport.TTransportException: Could not
> connect to localhost:9090
> >>>
almost same prbm with directly calling. In all, I just want to use hbase database instead of mongodb in my python application. No hadoop, no hdfs etc.Is it feasible or I am trying to achieve something impossible?
The Trift server hast to be up and running. Your connection has to be opened as well:
nohup hbase thrift start &
Open connection in python before use. Example:
import happybase
connection = happybase.Connection('localhost', autoconnect=False)
connection.open()

Categories