Can't connect to DB2 Driver through Python: SQL1042C - python

I can't connect to a DB2 remote server using Python. Here is what I've done:
Created a virtualenv with Python 2.7.10 (On Mac OS X 10.11.1)
installed ibm-db using sudo pip install ibm_db
Ran the following code:
import ibm_db
ibm_db.connect("my_connection_string", "", "")
I then get the following error:
Exception: [IBM][CLI Driver] SQL1042C An unexpected system error
occurred. SQLSTATE=58004 SQLCODE=-1042
I've googled around for hours and trying out different solutions. Unfortunately, I haven't been able to find a proper guide for setting the environment up on Mac OS X + Python + DB2.

Have you followed the setup instructions here?
https://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.swg.im.dbclient.python.doc/doc/t0054368.html
You need your DB2 ODBC driver properly installed before your Python code will work.
This issue may also shed light:
https://github.com/ibmdb/node-ibm_db/issues/34

I was able to reproduce the error 1042C in one of the mac machine.
Solution for the same is to set DYLD_LIBRARY_PATH to clidriver/lib/icc. I would suggest you set DYLD_LIBRARY_PATH to both clidriver/lib and clidriver/lib/icc For Eg:
export DYLD_LIBRARY_PATH=/Library/Python/2.7/site-packages/ibm_db-2.0.6-py2.7-macosx-10.10-intel.egg/clidriver/lib:/Library/Python/2.7/site-packages/ibm_db-2.0.6-py2.7-macosx-10.10-intel.egg/clidriver/lib/icc
I have python 2.7 installed in my machine and easy_install/pip install auto downloaded clidriver to /Library/Python/2.7/site-packages/ibm_db-2.0.6-py2.7-macosx-10.10-intel.egg/ directory.
Request you to set DYLD_LIBRARY_PATH as per your environment. Please let us know whether it solves your problem.

We are able to install the driver successfully and connection to db is established without any problem.
The steps are:
1) Upgraded to OS X El Capitan
2) Install pip - sudo pip install
3) Install ibm_db - sudo pip install ibm_db
4) During installation, below error was hit
Referenced from: /Users/roramana/Library/Python/2.7/lib/python/site-packages/ibm_db.so
Reason: unsafe use of relative rpath libdb2.dylib in /Users/roramana/Library/Python/2.7/lib/python/site-packages/ibm_db.so with restricted binary
After disabling the System Integrity Protection, installation went fine.
From the error sql1042c, it seems like you are hitting some environment setup issue.
You could try setting DYLD_LIBRARY_PATH to the path where you have extracted the odbc and cli driver .
If the problem still persist, please collect db2 traces and share with us:
db2trc on -f trc.dmp
run your repro
db2trc off
db2trc flw trc.dmp trc.flw
db2trc fmt trc.dmp trc.fmt
Share the trc.flw and trc.fmt files.

check your ibmdb connection parameters
conn=ibm_db.connect("DATABASE=dbname;HOSTNAME=hostname;PORT=32286;SECURITY=SSL;SSLSererCertificate=DigiCertGlobalRootCA.crt;UID=username;PWD=passwd",'','')
conn=ibm_db.connect("DATABASE=dbname;HOSTNAME=hostname;PORT=32286;SECURITY=SSL;SSLSererCertificate=DigiCertGlobalRootCA.crt;UID=username;PWD=passwd",'','')
Ensure that ssl certificate parameter --filename with extension
SSLSererCertificate=DigiCertGlobalRootCA.crt

Related

Trying to connect oracle db from python using cx_oracle and found "ppcx_Oracle.i386 : Python interface to Oracle" using yum list installed

When tried to import cx_Oracle getting error module not found.
Not sure what exactly "ppcx_Oracle.i386" is for and the way to utilize it.
=================================================================== Matched: ppcx_Oracle ====================================================================
ppcx_Oracle.i386 : Python interface to Oracle
is "ppcx_Oracle.i386" anything related to "cx_Oracle" package or i have to look for other options to install cx_Oracle to connect oracle database?
Environment : RHEL 5.4 and python 2.4,2.6
PS: Not having any issues in cx_Oracle since i have already used it in one of my servers.
Thanks in advance!!!
You should have Oracle Instant Client installed on the machine (or Oracle DB). The cx_oracle will use its shared libraries.
Then run this command to install cx_oracle itself:
python -m pip install cx_Oracle --upgrade
More on how to configure it and a code examples can be found here.
https://cx-oracle.readthedocs.io/en/latest/installation.html
ppcx_oracle.i386 looks like some non-official interface, I don't know it and could not give any recommendations about it.

Error "-fabi-version=2" when installing Msyqldb or Flask-mysqldb (or any mysql client) in PyCharm on Mac OS using AMPPS

I'm a beginner Python programmer and currently using pyCharm CE IDE on a MAC OS High Sierra system following a tutorial to create a database web-app.
The issue I am facing is when I try to add any mysql access library in 'requirements.txt' the installation fails. (tried with Flask-Mysqldb, mysqlclient, mysqldb)
I figured out that the issue i was facing earlier missing mysql_config was due to using AMPPS (Softaculous) MAMP stack and was able to fix it by updating my $PATH  variable to include the path to /Applications/AMPPS/mysql/bin
Now the error I am getting is
clang: error: unknown argument: '-fabi-version=2'
Most of the solutions I have come across are suggestions to replace MAMP MySQL with the homebrew version (or something similar). Ideally I would like to stick with AMPPS since I am familiar with this and have other apps currently hosted on it (e.g. Wordpress).
Resolved the issue by following the below steps:
modify mysql_config at /Applications/AMPPS/mysql/bin
Remove '-fabi-version=2' flag from 'cflags' (around line:122)
successfully install mysqlclient (or MySQLdb)

Google Cloud SDK install on OS X: (gcloud.components.list) Failed to fetch component listing from server

I'm trying to install the Google Cloud SDK (https://cloud.google.com/sdk/docs/quickstart-mac-os-x) and get this error:
ERROR: (gcloud.components.list) Failed to fetch component listing from server. Check your network settings and try again.
Already tried updating OpenSSL and corresponding Python (also tried Python 2.7.8):
openssl version
OpenSSL 1.0.2k 26 Jan 2017
python -V
Python 2.7.13
Python is also using this OpenSSL version:
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.2k 26 Jan 2017'
I'm running mac OS 10.12.4
I've also tried brew cask install google-cloud-sdk which effectively just downloads the normal version und executes the install.sh script. Same result.
Further debugging showed, it's unable to load https://dl.google.com/dl/cloudsdk/channels/rapid/components-2.json and throws this error: URLError: <urlopen error timed out>.
Loading this file via Python directly works:
urllib2.urlopen('https://dl.google.com/dl/cloudsdk/channels/rapid/components-2.json')
Any ideas? Also any hints how to further debug this, would be appreciated :)
After turning off ipv6 support, the tool works like a charm. Looks like gcloud can not work gracefully with ipv6...
Disable ipv6:
networksetup -setv6off Wi-Fi
Enable ipv6:
networksetup -setv6automatic Wi-Fi
Note: While investigating this, I was also able to make it work by using a very long timeout — 120 seconds. This wouldn't be practical, though, for most use cases due to the long delays it would introduce for each command.
The timeout is located in google-cloud-sdk/lib/googlecloudsdk/core/updater/installers.py at line 36 called TIMEOUT_IN_SEC
Disable IPV6 :
sysctl net.ipv6.conf.all.disable_ipv6=1
Disabling ipv6 didn't work for me. I tried a bunch of things before getting it to work.
I upgraded to mojave OSX before getting the issues.
I updated mac headers as mentioned here:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Rebooted then reinstalled python2:
brew reinstall python2
At this point the issue still persisted, decided to reinstall gcloud and came across this:
I was using zsh so I added the followin .zshrc:
source <PATH to gcloud sdk>/google-cloud-sdk/path.zsh.inc
source <PATH to gcloud sdk>/google-cloud-sdk/completion.zsh.inc
For bash:
source <PATH to gcloud sdk>/google-cloud-sdk/path.bash.inc
source <PATH to gcloud sdk>/google-cloud-sdk/completion.bash.inc`
Then a gcloud init got me resetting some proxy configuration that was probably the main issue from the start.

Can't get Python 3.2.5 and cx_Oracle to work

I need to connect to Oracle database using python. So, I did the following:
I downloaded instantclient_11_2 basic and sdk from Oracle site.
Put the files on /opt/ora/instantclient
export ORACLE_HOME=/opt/ora/instantclient
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
cd $ORACLE_HOME && ln -s libclntsh.so.11.1 libclntsh.so
Downloaded and installed cx_Oracle-5.1.1-11g-py32-1.x86_64.rpm
But when I tried to run import cx_Oracle I got this error:
ImportError: No module named cx_Oracle
According to cx_Oracle site I need to Place the file cx_Oracle.pyd or cx_Oracle.so anywhere on your Python path. But I can't find those files after installing cx_Oracle-5.1.1-11g-py32-1.x86_64.rpm..
By the way, I also tried to install using zipped version but I got a lot error upon building like error: command 'gcc' failed with exit status 1
Is there anything I did wrong?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Got it solved guys. I upgraded my python to latest, used cx_Oracle for python33, and instantclient11.2..
1: For your failed building, please give more details. Probably because you don't have the python development headers installed ("python-devel")
2: You need Oracle client installed as well, because cx_Oracle is just a linker between Python and the Oracle Client. Fast way is to get "Instant Client".
From the cx-oracle's README:
Please note that an Oracle client (or server) installation is required in order to use cx_Oracle. If you do not require the tools that come with a full client installation, it is recommended to install the Instant Client which is far easier to install.

cx_Oracle: ImportError: DLL load failed: This application has failed

Here's what I did:
I'm on Windows XP SP3
I already had Python 2.7.1 installed.
I downloaded instantclient-basic-nt-11.2.0.3.0.zip, unzipped it, and put it in C:\Program Files\Oracle\instantclient_11_2.
I added this path to the Windows Path environment variable.
I created a new environment variable ORACLE_HOME holding this path as its value.
I installed cx_Oracle-5.1.2-11g.win32-py2.7.msi.
And on running import cx_Oracle all I get is
Traceback (most recent call last):
File "<string>", line 2, in <module>
ImportError: DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
I obviously uninstalled / reinstalled cx_Oracle a couple of times but really nothing seems to help. Could anyone please provide a clue how to fix this?
UPDATE
I ran Dependency Walker and it comes up with a lot of trouble. However, the first missing .dll (msvcr80.dll) is actually present in C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.91_x-ww_0de56c07.
OK, what finally solved the problem (not sure whether all steps are necessary and no idea why exactly this and only this worked so far):
Download and unzip version 12 from here.
Add "ORACLE_HOME" as a Windows environment variable and set its value to ...\instantclient_12_1, (not its containing folder!).
Add this same path to the "Path" environment variable.
Only now install cx_Oracle.
To help other people with the same problem:
This error tells about 32-64 bit mismatch between some DLL while importing module. Possibilities are:
Different architecture of Python and cx_Oracle (less probable since cx_Oracle installer on Windows warns you if appropriate Python was not found).
Different architecture of cx_Oracle libraries and oci.dll (more probable).
Keep in mind that cx_Oracle uses standart Oracle client (at OCI level), which must be installed on your machine. It searches for oci.dll in several places, including PATH. If it finds oci.dll of wrong version of the client, the error appears.
In case you get this error, check path list in the PATH environment variable. It is likely to contain path to BIN folder of wrong version of Oracle client. If you have several clients, specify in the PATH the appropriate one, or install the appropriate client.
NOTE: ORACLE_HOME does not have an effect for cx_Oracle. In my case only changing of PATH helped. I think the Ruben's solution works because of item 3 ('Add this same path to the "Path" environment variable').
I am using python35 64 bit and oracle express on win 7 (64 bit).
I installed cx_Oracle using pip3 (pip3 install cx_Oracle) instead of downloading the installer from pypi.
I faced the same problem.
I solved it by following above guidelines, but instead of 32 bit client, I downloaded the 64 bit version of the instant client (instantclient-basic-windows.x64-11.2.0.4.0.zip) from http://www.oracle.com/technetwork/topics/winx64soft-089540.html.
I then extracted it to c:\oraclexe. And added these environment variables
set ORACLE_BASE=C:\oraclexe
set ORACLE_HOME=C:\oraclexe\app\oracle\product\11.2.0\server
set PATH=C:\oraclexe\instantclient_11_2;%PATH%
And ran my django migrate commands:
python manage.py migrate
It worked excellent
Easy way:
Make sure you have installed cx-Oracle, I have cx_Oracle-5.1.3-11g.win32-py2.7.exe
Download, unzip instantclient_12_1 and move it to C:\Python27
Add environment variable C:\Python27\instantclient_12_1
Restart your computer
Same ImportError occured for setup of:
Windows 10 x64
Oracle Instant Client 12_1 x64
Python 2.7.11 x64
cx_Oracle cx_Oracle-5.2-12c.win-amd64-py2.7
I solved it copying msvcr100.dll file into <oracle_instant_client_dir>
Had this issue also, and it seems importing cx_Oracle (at least as of 5.1.2) will fail (with the same error) if you have any invalid/unreachable UNC paths in front of Oracle in the PATH environment variable.
Fixing the UNC path (which was unrelated to Oracle) resolved the problem.
If you're using conda as a package manager, one way to overcome the DLL issue it to install oracle-instantclient by doing a conda install oracle-instantclient. This fixed the dependency which I couldn't fix by manually installing Oracle's instant-client.
As is the second time I came to this question, I feel the need to post what I did:
I'm using:
Win 8 64 bits
Python 2.7
I had no success installing Python and cx_Oracle 64 bits.
It only worked when I tried 32 bits versions and followed #rob answer instructions
I had same issue with DLL load failed on my Windows machine.
installed oracle client, set variables, ran cx_Oracle-5.1.3-11g.win32-py2.7.exe file.
however when I installed cx_Oracle with easy_setup it fixed the problem.
C:\Python27\Scripts\easy_install.exe cx_Oracle-5.1.3-11g.win32-py2.7.exe
Steps I have followed :
Downloaded the smart client instantclient-basic-windows.x64-12.1.0.2.0.zip
Extracted and copied to #your directory#\instantclient_12_1
Above directory contains dll's
Append the PATH variable with #your directory#\instantclient_12_1 and created env variable ORACLE_HOME= #your directory#\instantclient_12_1
Download and install cx_Oracle-5.2.1-11g.win-amd64-py2.7.exe
Open idle type import cx_Oracle
if you're using Anaconda on Windows try:
conda install cx_oracle
on your cmd
-> this
I know this is an old post, but I had this problem today and none of the solutions worked. I figure this could work for others with the same problem as of now.
Python version : 2.7.15 (64 bits)
cx_Oracle version : 6.4.1
Oracle Instant Client : 18.3
I kept getting the following error even though I followed evry steps in the correct order :
cx_Oracle.DatabaseError: DPI-1047: Oracle Client library cannot be loaded
I solved it by downgrading my Oracle Instant Client version to 12.1

Categories

Resources