Sample connection for HIVE and Python - python-2.7

I am trying to connect python with hive data base .
Both are on different server.
hive resides on host xx.xxx.xxx.x and python is on my local system.
i am trying to use the below code , however its not working
import pyhive
from pyhive import hive
conn = hive.connect(host = 'xx.xxx.xx.xx', port = 8888, auth = 'KERBEROS', kerberos_service_name='adsuedscaihen01.aipcore.local', username ='user1', database = 'database1'
)
cur = conn.cursor()
cur.execute('SELECT * from table1')
result = cur.fetchall()
print(result)
while i run the above code , i am facing the below error:
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/pyhive/hive.py", line 64, in connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/pyhive/hive.py", line 162, in init
self._transport.open()
File "/usr/lib/python2.7/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 (-1) SASL(-1): generic failure: GSSAPI Error: Unspecified GSS failure. Minor code may provide more information (Server not found in Kerberos database)

Related

Unable to connect to Teradata using Anaconda 4.3.1(64-bit) with Python 2.7.13

I am unable to achieve teradata connectivity using python. I have anaconda set up 4.3.1(64-bit) with python 2.7.13. Further i installed teradata odbc client driver for 16.20 and configured the odbc.ini file with user DSN details.
I have tried the options mentioned in this article -
https://github.com/Teradata/PyTd/issues/43
https://github.com/Teradata/PyTd/issues/89
import teradata
import os, sys
os.environ["ODBCINI"] ="/opt/teradata/client/16.20/odbc_64/odbc.ini"
os.environ["O`enter code here`DBCINST"] ="/opt/teradata/client/16.20/odbc_64/odbcinst.ini"
os.environ["LD_LIBRARY_PATH"] ="/opt/teradata/client/16.20/odbc_64/lib"
udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0", odbcLibPath="/opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so")
session = udaExec.connect(method="odbc", system="tdprod", username="xxxxx", password="yyyyy")
for row in session.execute("SELECT GetQueryBand();"):
print(row)
Below is the execution log and error message of this script -
[servername#python]$ python test_teradata.py
Traceback (most recent call last):
File "test_teradata.py", line 17, in
session = udaExec.connect(method="odbc", system="tdprod", username="xxxxx", password="yyyyy")
File "/.../.../anaconda/lib/python2.7/site-packages/teradata/udaexec.py", line 183, in connect
**args))
File "/.../.../anaconda/lib/python2.7/site-packages/teradata/tdodbc.py", line 421, in __init__init(odbcLibPath)
File "/.../.../anaconda/lib/python2.7/site-packages/teradata/tdodbc.py", line 367, in init initFunctionPrototypes()
File "/.../.../anaconda/lib/python2.7/site-packages/teradata/tdodbc.py", line 298, in initFunctionPrototypes prototype(odbc.SQLDrivers, SQLHANDLE, SQLUSMALLINT, PTR(SQLCHAR),
File "/.../.../anaconda/lib/python2.7/ctypes/init.py", line 375, in __getattr__func = self.getitem(name)
File "/.../.../anaconda/lib/python2.7/ctypes/init.py", line 380,in __getitem__func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so: undefined symbol: SQLDrivers
If supplied, the odbcLibPath should point to the ODBC Driver Manager (libodbc.so), not the ODBC Driver itself.
If the wrong driver is being selected, then add explicit driver= parameter to the connect arguments, e.g. driver="Teradata Database ODBC Driver 16.20".`

Read user email contents using imaplib2

I'm writing a python code to read email from mail server(neither google nor outlook) using imaplib2 package. I'm getting the following error with my code. Can anybody tell me how could I fix it. Do I need to use only port=993 and host=imap, if so how can I connect to the server I need to
import imaplib2
import base64
email_user = 'mailid'
email_pass = 'password'
email_server = 'ns21.interactivedns.com'
Mail = imaplib2.IMAP4_SSL(email_server, 995) # used this server and port since I'm trying to read mail contents from this server
Mail.login(email_user, email_pass)
Mail.select('Inbox')
type, messages = Mail.search(None, 'ALL')
Error I'm gertting:
Traceback (most recent call last):
File "C:/Users/user01/PycharmProjects/MongoAlchemy/client.py", line 6, in <module>
M = imaplib2.IMAP4_SSL('ns21.interactivedns.com', 995)
File "C:\Users\user01\PycharmProjects\MongoAlchemy\venv\lib\site-packages\imaplib2\imaplib2.py", line 2073, in __init__
IMAP4.__init__(self, host, port, debug, debug_file, identifier, timeout, debug_buf_lvl)
File "C:\Users\user01\PycharmProjects\MongoAlchemy\venv\lib\site-packages\imaplib2\imaplib2.py", line 392, in __init__
raise self.error('unrecognised server welcome message: %s' % repr(self.welcome))
imaplib2.imaplib2.error: unrecognised server welcome message: None

How to connect Python and neo4j?

I am new to neo4j and want it to connect with Python. I am using neo4j version 3.0.3 and following this tutorial.
I put the code below in my Python file, I have changed the password, since my password is root:
from neo4j.v1 import GraphDatabase, basic_auth
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth(user = "neo4j", password = "root"))
session = driver.session()
session.run("CREATE (a:Person {name:'Bob'})")
result = session.run("MATCH (a:Person) RETURN a.name AS name")
for record in result:
print(record["name"])
session.close()
But on running it, I am getting following errors:
Traceback (most recent call last):
File "D:/Work/MySQL_neo4j_Importer/dumping_ingredients.py", line 3, in <module>
session = driver.session()
File "C:\Python27\lib\site-packages\neo4j\v1\session.py", line 148, in session
session = Session(self)
File "C:\Python27\lib\site-packages\neo4j\v1\session.py", line 461, in __init__
self.connection = connect(driver.host, driver.port, driver.ssl_context, **driver.config)
File "C:\Python27\lib\site-packages\neo4j\v1\connection.py", line 403, in connect
s = create_connection((host, port))
File "C:\Python27\lib\socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed
I have also tried this StackOverFlow answer as well, but, the result remains same.
For Neo4j 1.8 / 1.9 / 2.0 / 2.1 / 2.2 / 2.3 you could use Py2neo.
Here you can find an exhaustive list of python drivers

pyhs2 error connective to kerberos enabled hive

I am trying to connect to hive using python 2(miniconda2 installation ).
Below is the code I am trying-
connection = hive.connect(host='psvlxihpnn1', port= '10000', authMechanism='KERBEROS', user='***',password='****', configuration={'krb_host': 'psvlxihpnn1', 'krb_service': 'ITEDM'} )
kerberos host is installed on the same host machine and has service name 'ITEDM'
Strangely, I am getting below error-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/export/home/itedm/miniconda2/lib/python2.7/site-packages/pyhs2-0.6.0-py2.7.egg/pyhs2/__init__.py", line 7, in connect
File "/export/home/itedm/miniconda2/lib/python2.7/site-packages/pyhs2-0.6.0-py2.7.egg/pyhs2/connections.py", line 46, in __init__
File "/export/home/itedm/miniconda2/lib/python2.7/site-packages/pyhs2-0.6.0-py2.7.egg/pyhs2/cloudera/thrift_sasl.py", line 66, in open
thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-1) SASL(-1): generic failure: GSSAPI Error: Unspecified GSS failure. Minor code may provide more information (Server krbtgt/INFORMATICA.COM#ITEDM not found in Kerberos database)
I am not passing 'krbtgt' as user, not sure why this error is coming.
Thanks for any help.
This connection string will work as long as the user running the script has a valid kerberos ticket:
import pyhs2
with pyhs2.connect(host='beeline_host',
port=10000,
authMechanism="KERBEROS") as conn:
with conn.cursor() as cur:
print cur.getDatabases()
Username, password and any other configuration parameters are not passed through the KDC.

failed connect QGIS plugin with access 2007 database using pyodbc

I m Running Win 7 32 bit and i using python 27, i try to connect ms-access database in my QGIS plugin using pyodbc, but when i launch it i have a following error :
Traceback (most recent call last):
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 204, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\__init__.py", line 26, in classFactory
from testdbase import TestDbase
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 453, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\testdbase.py", line 29, in
from testdbasedialog import TestDbaseDialog
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 453, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\testdbasedialog.py", line 28, in
r'DBQ=C:\__tmp\test1.accdb')
Error: ('HY024', "[HY024] [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. (-1023) (SQLDriverConnect); [HY024] [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. (-1023)")
And i place it like this in my code :
from PyQt4 import QtCore, QtGui
from ui_testdbase import Ui_TestDbase
import pyodbc
db = pyodbc.connect(
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};' +
r'DBQ=C:\__tmp\test1.accdb')
class TestDbaseDialog(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_TestDbase()
self.ui.setupUi(self)
Rec_1 = self.ui.btnOke
QtCore.QObject.connect(Rec_1, QtCore.SIGNAL('clicked()'),self.Compskala)
def Compskala(self):
skal1 = self.ui.lineSkal1.text()
skal2 = self.ui.lineSkal2.text()
bandskal = ''
if skal1 == skal2:
bandskal = 'Kedua Peta dapat dipadukan'
I really a newb in this, so can someone give me a help?
Substituting backslashes for forward slashes in the filename seems to work:
Fails
>>> db = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" +
"DBQ=C:\__tmp\test.accdb")
Traceback (most recent call last): File "", line 1, in
pyodbc.Error: ('HY000', '[HY000] [Microsoft][ODBC Microsoft
Access Driver] Not a valid file name. (-1044) (SQLDriverConnect)')
Succeeds
>>> db = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" +
"DBQ=C:/__tmp/test.accdb")
>>> connection.getinfo(pyodbc.SQL_SERVER_NAME)
'ACCESS'