DB2 connection issue in python after change and update of SSL - python

I am trying to establish a connection to DB2 which was working fine but after the change and update of SSL, it gave this error: com.ibm.db2.jcc.am.DisconnectNonTransientException: [jcc][t4][2034][11148][4.27.25] Execution failed due to a distribution protocol error that caused deallocation of the conversation. A DRDA Data Stream Syntax Error was detected. Reason: 0x3. ERRORCODE=-4499, SQLSTATE=-58009. Despite I had updated the cert and did the set up of the connection settings and connection was ok, the codes are giving this error. Can anyone help to advice where did I miss out or anything wrong with my script pls.
import os
from subprocess import Popen, PIPE, run
import jaydebeapi
from project_lib import Project
project = Project.access()
abc_connection = project.get.connection(name="abc")
abc_connection = jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver',
'{}://{}:{}/{}:user={};password={};'.format('jdbc:db2',
abc_credentials['host'],
abc_credentials['port'],
abc_credentials['database'], '/project_data/data_asset/ssl_cert.crt',
abc_credentials['username'],
abc_credentials['password']))
curs = abc_connection.cursor()
Any help is appreciated. Thanks.

Related

metatrader error initialize() failed, error code = (-10005, 'IPC timeout')

I got this error
initialize() failed, error code = (-10005, 'IPC timeout')
when execute this code:
import MetaTrader5 as mt5
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
# establish connection to the MetaTrader 5 terminal
if not mt5.initialize(login=999999, server="xyz-Demo",password="abcdef"):
print("initialize() failed, error code =",mt5.last_error())
mt5.shutdown()
Can anyone help me please? Thanks in advance
There might be some solutions to your problem:
Try initializing a connection to the MT5 terminal using mt5.initialize() then login into the trading account using mt5.login(account, server, password).
Try closing all previous connections to the mt5 terminal using mt5.shutdown() on all previous scripts
This is how I solved it.
I divided the process into two:
I did the initialization and then,
I logged in.
Importantly, I'm using a Windows PC and everything started working when I changed the path from
"C:\Program Files\MetaTrader 5\terminal64.exe"
to
"C:/Program Files/MetaTrader 5/terminal64.exe"
The code:
def account_login(login = name,password=key, server= serv,):
if mt5.login(login,password,server):
print("logged in succesffully")
else:
print("login failed, error code: {}".format(mt5.last_error()))
def initialize(login = name, server=serv, password=key, path=path):
if not mt5.initialize(path):
print("initialize() failed, error code {}", mt5.last_error())
else:
account_login(login, password, server)
Maybe, We must launch the app.
In actually, I solved same issue by launch the app.

connect db2 using python with securityMechanism=13

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>;", "", "")

Why smbprotocol connection is getting timeout

I'm trying to transfer some file from ubuntu to Window(AWS EC2 instance).But I'm getting following error.
ValueError: Failed to connect to '35.154.105.236': timed out
For reference
import smbclient
import sys
# Optional - register the credentials with a server
print(smbclient.register_session("35.154.105.236", username="Administrator", password="XXXXXXXXXXX"))
May I know what is missing and why it is getting timeout.

Python - Jaydebeapi/jpype - Connect to to as400/db2 with ssl encryption

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.

Python 3 Read data from URL [duplicate]

I have this simple minimal 'working' example below that opens a connection to google every two seconds. When I run this script when I have a working internet connection, I get the Success message, and when I then disconnect, I get the Fail message and when I reconnect again I get the Success again. So far, so good.
However, when I start the script when the internet is disconnected, I get the Fail messages, and when I connect later, I never get the Success message. I keep getting the error:
urlopen error [Errno -2] Name or service not known
What is going on?
import urllib2, time
while True:
try:
print('Trying')
response = urllib2.urlopen('http://www.google.com')
print('Success')
time.sleep(2)
except Exception, e:
print('Fail ' + str(e))
time.sleep(2)
This happens because the DNS name "www.google.com" cannot be resolved. If there is no internet connection the DNS server is probably not reachable to resolve this entry.
It seems I misread your question the first time. The behaviour you describe is, on Linux, a peculiarity of glibc. It only reads "/etc/resolv.conf" once, when loading. glibc can be forced to re-read "/etc/resolv.conf" via the res_init() function.
One solution would be to wrap the res_init() function and call it before calling getaddrinfo() (which is indirectly used by urllib2.urlopen().
You might try the following (still assuming you're using Linux):
import ctypes
libc = ctypes.cdll.LoadLibrary('libc.so.6')
res_init = libc.__res_init
# ...
res_init()
response = urllib2.urlopen('http://www.google.com')
This might of course be optimized by waiting until "/etc/resolv.conf" is modified before calling res_init().
Another solution would be to install e.g. nscd (name service cache daemon).
For me, it was a proxy problem.
Running the following before import urllib.request helped
import os
os.environ['http_proxy']=''
response = urllib.request.urlopen('http://www.google.com')

Categories

Resources