I'm trying to connect db2 using python but I don't know how to set the securityMechanism=13 property correctly can you please tell me how to do this?
import jaydebeapi
conn_src = jaydebeapi.connect(
'com.ibm.db2.jcc.DB2Driver',
'jdbc:db2://host:port/dbname',{"encryptionAlgorithm":"2",'securityMechanism':'13', 'user':'username',"password":'pass'},'',
)
cursor=conn_src.cursor()
ERROR MESSAGE:
com.ibm.db2.jcc.am.SqlExceptionPyRaisable:
com.ibm.db2.jcc.am.SqlException: [jcc][t4][10441][12439][3.69.66]
encryptionAlgorithm can only be set with securityMechanism
ENCRYPTED_PASSWORD_SECURITY and ENCRYPTED_USER_AND_PASSWORD_SECURITY.
ERRORCODE=-4450, SQLSTATE=null
I would be happy to use ibm_db, but I did not find a way to set securityMechanism=13.
Have received the same Error when trying to connect via Jaydebeapi, but when I tried to connect with ibm_db_dbi it works without any error.
Below script works fine and no need to mention 'securityMechanism' explicitly.
#Header
from ibm_db_dbi import connect
#Connection string
conn_src = connect("DATABASE=<DB_Name>;
HOSTNAME=<Host_Name>;
PORT=50000;PROTOCOL=TCPIP;
UID=<username>;PWD=<password>;", "", "")
Related
I try to connect to SQL using the pyodbc package, but get the error:
SystemError:
built-in function connect returned NULL without setting an error
What could be the reason for this?
When I run the code from another computer - I do manage to connect to SQL.
The connection string I use:
conn_str = 'DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + database + ';'
conn = pyodbc.connect(conn_str)
I have ODBC and pyodbc installed on my computer.
Of course I set values for the database and server fields
Before I do connect I use a function that does logon with the username and password
Because of your question do not have a reproductible exemple i can't be 100% of what I will say;
This is probably a driver problem, if you have acces to db2dsdriver.cfg file or db2cli.ini you shoyld try to look in those files to find what is the exact name of the driver.
Following this could help you to have more information on the problem.
I am trying to connect to remote hive using pyHive.
conn = hive.Connection(host='*********', port=10001, database='default', username='********',
auth='KERBEROS', kerberos_service_name='hive').cursor()
But I always got this error
**Notes: I already have the kerberos ticket
Is there something wrong with my configuration ?
im struggling (since a few days) to connect to our db2 database on an as400 over ssl.
For the database connection im using jaydebeapi and to access the database with a secure connection i need to append the trustStore location and trustStore password to the JVM over a jpype function.
Here is a snipped what ive done so far:
import jaydebeapi
import os
import jpype
import pandas as pd
from credentials_getter import get_db2_credentials
class i5Connection:
def __init__(self, user, password):
if jpype.isJVMStarted():
print("already started!")
filepath_script = os.path.dirname(os.path.abspath(__file__))
ssl_trust_store_location = filepath_script + "/database/java-certs.jks"
jar = filepath_script + '/database/jt400.jar'
jvm_path = jpype.getDefaultJVMPath()
jpype.startJVM(jvm_path,
'-Djava.class.path=%s' % jar,
'-Djavax.net.ssl.trustStore=%s' % ssl_trust_store_location +
'-Djavax.net.ssl.trustStorePassword=pw')
connection_string = 'jdbc:as400://172.17.0.1/library'
print(connection_string)
self.conn = jaydebeapi.connect('com.ibm.as400.access.AS400JDBCDriver',
connection_string,
{'user': user,
'password': password,
'secure': 'true'},
filepath_script + '/database/jt400.jar')
Right now im running into the following error message:
jpype._jexception.java.sql.SQLExceptionPyRaisable: java.sql.SQLException: The application requester cannot establish the connection. (PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target)
If i remove the trustStoreLocation, password from the startJVM call and the secure parameter for the jaydebeapi call, it works (without encryption)
Can anyone please tell me what im doing wrong? Is there probably a good ibm documentation i didnt find yet?
Edit: Ive found a workaround: I just saved the certificate to the cacert manually via keytool: How do I import an existing Java keystore (.jks) file into a Java installation?
not really a solution, but hopefully helpful if someone is stuck as well...
This isn't a JayDeBeApi solution, but I am able to connect to HANA using Python with an encrypted connection using this solution on a Mac and Windows.
I'm trying to connect using:
conn = DBAPI.connect(host='sql2', user='XXX', password='XX', database='XX', socket_timeout=100, port=100)
I now find I get the following error:
pg8000.errors.InterfaceError: Authentication method 3 not supported by pg8000.
Looking around I get what this may mean:
3 = Cleartext pwd (not supported by pg8000)
Are there any suggestions here?
The latest version (1.9.14) of pg8000 supports password authentication.
There doesn't seem to be any great instructions for setting this up. Does anyone have any good instructions? I am a linux noob so be gentle. I did see another post that is similar, but no real answer.
I have a couple of problems.
FreeTDS doesn't "seem" to be working. I am trying to connect and I get the following message using the "tsql" command: "Default database being set to databaseName
There was a problem connecting to the server" but it doesn't mention what the problem is.
The error I get when I try to connect using pyodbc is: "pyodbc.Error: ('08S01', '[08S01] [unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist (20009) (SQLDriverConnectW)')"
I tried something similar with pymssql, but I ran into similar issues. I keep getting errors that I can't connect, but it doesn't tell me why.
The following works if you configure the MS SQL server to allow remote TCP/IP connections and have an appropriate user to connect as.
You also need to be careful to set up the correct hostname for the db as reported by MS SQL.
import pymssql
connection = pymssql.connect(
user = 'username',
password = 'password',
host = 'server',
database = 'database',
)
cursor = connection.cursor()
cursor.execute('select * from db;')
rows = cursor.fetchall()
When building FreeTDS (http://www.freetds.org/userguide/config.htm):
./configure --with-tdsver=8.0 --enable-msdblib
That error suggests that the TDS version is not set right. You can set that in the configuration setting for FreeTDS. You don't mention which MSSQL version you are using. But, if you are using say 2005, setting 8.0 as the TDS version will work.