pythonQuery.py
and make sure sslValidateCertificate=True
is set and try it on Windows 10, Linux (Ubuntu), and MacOS Catalina.#Import your dependencies
import platform
from hdbcli import dbapi
#verify that this is a 64 bit version of Python
print ("Platform architecture: " + platform.architecture()[0])
#Initialize your connection
conn = dbapi.connect(
#address='hxehost',
#port='39015',
#user='User1',
#password='Password1',
key='HCUSER1UserKey', # address, port, user and password are retreived from the hdbuserstore
encrypt=True, # must be set to True when connecting to HANA Cloud
sslValidateCertificate=True # True HC, False for HANA Express.
)
#If no errors, print connected
print('connected\n')
cursor = conn.cursor()
sql_command = "select TITLE, FIRSTNAME, NAME from HOTEL.CUSTOMER;"
cursor.execute(sql_command)
rows = cursor.fetchall()
for row in rows:
for col in row:
print ("%s" % col, end =" ")
print ("")
cursor.close()
conn.close()
In my case I use HCUSER1UserKey
from HANA Clients User Store, which is the one connecting to my HANA Cloud instance. But -- again -- the same would apply to connect to an HDI Container in SCP Trial.
mscrypto
. So, not much new fun here.python3 pythonQuery.py
fails with hdbcli.dbapi.Error: (-10709, 'Connection failed (RTE:[300010] Cannot create SSL context: SSL trust store cannot be found: /home/vitaliy/.ssl/trust.pem
error.~/.ssl/trust.pem
file 🙂 Another way is to search the required certificate, if already available on the OS.requests
package for HTTP communication, which requires CA certificates for secure communication too. Therefore it comes with one other package dependency: certifi
-- package for providing Mozilla's CA Bundle.pip search certifi
and indeed I have it already... the version from 2018, when I stopped actively working on IoT examples. Ah, nostalgia... But, let's get back to reality.certifi (2020.4.5.1) - Python package for providing Mozilla's CA Bundle.
INSTALLED: 2018.1.18
LATEST: 2020.4.5.1
Now, before you jump on upgrading it (just the way I did at first), please read the Erratum part at the bottom of the blog. At least if you are at Ubuntu 18.04, as I was.
pip3 install certifi
certifi
now. I saved it as pythonQuerySecure.py
now.#Import your dependencies
import platform
from hdbcli import dbapi
import certifi
#verify that this is a 64 bit version of Python
print ("Platform architecture: " + platform.architecture()[0])
#Initialize your connection
conn = dbapi.connect(
#address='10.7.168.11',
#port='39015',
#user='User1',
#password='Password1',
key='HCUSER1UserKey', # address, port, user and password are retreived from the hdbuserstore
encrypt=True, # must be set to True when connecting to HANA Cloud
sslValidateCertificate=True, # True HC, False for HANA Express.
sslTrustStore=certifi.where()
)
#If no errors, print connected
print('connected\n')
cursor = conn.cursor()
sql_command = "select TITLE, FIRSTNAME, NAME from HOTEL.CUSTOMER;"
cursor.execute(sql_command)
rows = cursor.fetchall()
for row in rows:
for col in row:
print ("%s" % col, end =" ")
print ("")
cursor.close()
conn.close()
python3 pythonQuerySecure.py
certifi
Python package was there as well...pip install --upgrade certifi
pip show certifi
python3 -m certifi
python3 -m certifi -c | grep "DigiCert Global Root CA"
...the problem was Abort trap: 6
error...
...
Path: /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python
...
OS Version: Mac OS X 10.15.4 (19E287)
Report Version: 12
...
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
/usr/lib/libssl.dylib
abort() called
Invalid dylib load. Clients should not load the unversioned libssl dylib as it does not have a stable ABI.
...
MacOS's openssl
is a version based on LibreSSL fork.
brew install openssl
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/opt/openssl/lib:$DYLD_FALLBACK_LIBRARY_PATH
.vscode/launch.json
file and add to configurations
:"env": {
"DYLD_FALLBACK_LIBRARY_PATH": "/usr/local/opt/openssl/lib"
}
certifi
too.pip search certifi
showed me I had some 2018 version on my computer with Ubuntu 18.04 as an OS.INSTALLED: 2018.1.18
pip install --upgrade certifi
pip show certifi
python3 -m certifi
python3 -m certifi -c | grep "DigiCert Global Root CA"
~/.local/lib/python3.6/site-packages/certifi/cacert.pem
with the up-to-date CA certificates bundle.pip install ...
.python3 pythonQuerySecure.py
and ... for hours, I stuck with that "hdbcli.dbapi.Error: (-10709, 'Connection failed (RTE:[89008] Socket closed by peer
" error.certifi
's ~/.local/lib/python3.6/site-packages/certifi/cacert.pem
with /etc/ssl/certs/ca-certificates.crt
-- everything worked too. I really stuck until I ran the following next to each other:dpkg -l | grep python3-certifi
pip3 search certifi
python3-certifi
installed together with Python3, and its latest version on my Ubuntu 18.04 is indeed 2018.1.18-2
: https://packages.ubuntu.com/bionic/python3-certifi.pip3 uninstall certifi
sudo apt-get install --reinstall python3-certifi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
18 | |
13 | |
13 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 |