Informix

Informix

Connect with Db2, Informix, Netezza, open source, and other data experts to gain value from your data, share insights, and solve problems.

 View Only
Expand all | Collapse all

Cannot connect to Informix database via Python

  • 1.  Cannot connect to Informix database via Python

    Posted Mon May 05, 2025 10:37 AM

    I am trying to modify an existing Python script that has run in a customer environment, but fails to connect in any of my local environments: Windows, Ubuntu or CentOS. They all return essentially the same error using packages SQLAlchemy, ibm_db of IfxPy:

    Exception: [IBM][CLI Driver] SQL30081N  A communication error has been detected. Communication protocol being used: "TCP/IP".  Communication API being used: "SOCKETS".  Location where the error was detected: "xxx".  Communication function detecting the error: "recv".  Protocol specific error code(s): "*", "*", "0".  SQLSTATE=08001 SQLCODE=-30081

    I have simplified the script:

    import ibm_db

    conn_str = "DATABASE=mydb;HOSTNAME=myhost;PORT=portnum;PROTOCOL=TCPIP;UID=myuser;PWD=mypw;SERVER=mydbs"
    conn = ibm_db.connect(conn_str, "", "")

    Does anyone have any idea what may be the cause for the error?



    ------------------------------
    Malcom Terry
    ------------------------------


  • 2.  RE: Cannot connect to Informix database via Python

    Posted Mon May 05, 2025 10:50 AM

    what is in your sqlhosts file ?

    On 5/5/2025 7:37 AM, Malcom Terry via IBM TechXchange Community wrote:
    01000196a0e1356a-c9bb359d-2d22-42dc-b2c3-e548d7b5fa47-000000@email.amazonses.com">
    I am trying to modify an existing Python script that has run in a customer environment, but fails to connect in any of my local environments:... -posted to the "Informix" group





  • 3.  RE: Cannot connect to Informix database via Python

    Posted Wed May 07, 2025 12:46 PM

    onlinedsa    onipcshm    frkpvreact01    def
    onlinedsasoc    onsoctcp    frkpvreact01    infmx_frkpvreact01



    ------------------------------
    Malcom Terry
    ------------------------------



  • 4.  RE: Cannot connect to Informix database via Python

    Posted Mon May 05, 2025 11:01 AM

    I am not sure, but you may want to try changing the protocol to drsoctcp or onsoctcp.



    ------------------------------
    Mike Walker
    xDB Systems, Inc
    www.xdbsystems.com
    ------------------------------



  • 5.  RE: Cannot connect to Informix database via Python

    Posted Wed May 07, 2025 12:58 PM

    Yep, 30081 I know as DRDA connection error (https://www.ibm.com/docs/en/db2/11.5.x?topic=errors-sql30081n-tcpip-communication), which is quite expected if there's no DRDA port/listener configured.

    -> you'll need another listener (DBSERVERALIASES entry) in your onconfig and a related line in sqlhosts using drsoctcp protocol.

    All this assuming you're bound to using the Db2 DRDA driver rather than an Informix SQLI driver to connect your application to Informix.
    Others will be able to point you to the native Informix Python driver.

    Andreas



    ------------------------------
    Andreas Legner
    Informix Dev
    HCL Software
    ------------------------------



  • 6.  RE: Cannot connect to Informix database via Python

    Posted Thu May 08, 2025 04:49 AM
    Edited by Benjamin Thompson Thu May 08, 2025 05:01 AM

    Malcolm,

    I would recommend using IfxPy and not the ibm_db driver which is really for DB2. This was just a stop-gap solution that works because Informix can accept connections from DB2 client tools on drsoctcp listeners but as it is not actually DB2, you may find some complications or missing features when you get into the actual coding. Dependent on what you are doing of course.

    If you install and use the IfxPy driver you will be able to connect through either TCP to your listener onlinedsasoc or shared memory to onlinedsa if running locally on the machine.

    Here is code I use to connect which uses sqlhosts

    import IfxPy

    import sys

    ConStr = "SERVER=onlinedsasoc;DATABASE=sysmaster;HOST=frkpvreact01;SERVICE=infmx_frkpvreact01"

    try:

        conn = IfxPy.connect( ConStr, "", "")

    except Exception as e:

            print ('ERROR: Connect to sysmaster database failed')

            print ( e )

            sys.exit(1)

    You may need to add the user and password details to your connection string.

    I hope this helps,

    Ben.



    ------------------------------
    Benjamin Thompson
    ------------------------------



  • 7.  RE: Cannot connect to Informix database via Python

    Posted Thu May 08, 2025 02:22 PM

    Thanks Benjamin,

    I tried "pip install IfxPy" on Windows 11 and on Ubuntu 22.04. Both return error:

    error in IfxPy setup command: use_2to3 is invalid

    It seems that latest releases of setuptools have removed that package. Also, IfxPy hasn't been maintained since 2020.  

    --Malcom Terry



    ------------------------------
    Malcom Terry
    ------------------------------



  • 8.  RE: Cannot connect to Informix database via Python

    Posted Fri May 09, 2025 04:18 AM

    Hi Malcom,

    I followed following document and it worked for me using sqlhosts onsoctcp protocol.

    https://github.com/OpenInformix/IfxPy

    Note: Client SDK should be installed and LD_LIBRARY_PATH should be exported.

    Regards,

    Nandkishor



    ------------------------------
    Nandkishor Singare
    ------------------------------



  • 9.  RE: Cannot connect to Informix database via Python

    Posted Fri May 09, 2025 04:25 AM

    Malcolm,

    I thought we might get to the problem being the installation. I use Rocky or RHEL 8 which ships with the slightly ancient Python 3.6 which may be why it works for me.

    With Client SDK installed, my installation steps are:

    dnf install rpm-build gcc python3 python3-pip python3-libs python3-devel -y

    export CSDK_HOME=/path/to/csdk

    export INFORMIXDIR=/path/to/csdk

    pip3 install ifxpy

    Have you seen https://stackoverflow.com/questions/72414481/error-in-anyjson-setup-command-use-2to3-is-invalid as the error you have posted looks to be a common issue and has a workaround you can try related to setuptools?

    Otherwise the drsoctcp listener and ibm_db driver might be your only option. I will ask HCL about the IfxPy driver next time I am on a call with them.

    Ben.



    ------------------------------
    Benjamin Thompson
    ------------------------------



  • 10.  RE: Cannot connect to Informix database via Python

    Posted 27 days ago

    Ben,

    I've tried many of the suggested things in the link about use_2to3 error and nothing has worked. I even tried to install without pip, python setup.py install, and gcc failed to compile. I think IfxPy is just too old and not compatible with modern Linux releases.

    I have also tried Python packages SQLAlchemy and ibm_db. They both refuse to connect eith error:
    Exception: [IBM][CLI Driver] SQL30081N  A communication error has been detected. Communication protocol being used: "TCP/IP".  Communication API being used: "SOCKETS".  Location where the error was detected: "x.x.x.x".  Communication function detecting the error: "recv".  Protocol specific error code(s): "*", "*", "0".  SQLSTATE=08001 SQLCODE=-30081

    The only client I have been able to connect with is DBeaver 25.0.5:

    So we know we can connect to the database, just not with any Python drivers.

    I tried all this on CentOS 10 and Ubuntu 22.04.

    Thanks,

    Malcom



    ------------------------------
    Malcom Terry
    ------------------------------



  • 11.  RE: Cannot connect to Informix database via Python

    Posted 27 days ago

    I believe HCL has done a fix in the last week or so to the IfxPy code. Have you seen this and tried it?

    Ben.



    ------------------------------
    Benjamin Thompson
    ------------------------------



  • 12.  RE: Cannot connect to Informix database via Python

    Posted 27 days ago

    Where may I find it? It's not on pypi.org.



    ------------------------------
    Malcom Terry
    ------------------------------



  • 13.  RE: Cannot connect to Informix database via Python

    Posted 27 days ago

    https://github.com/OpenInformix/IfxPy



    ------------------------------
    Benjamin Thompson
    ------------------------------



  • 14.  RE: Cannot connect to Informix database via Python

    Posted 27 days ago

    Ben,

    I found it and see that some changes have be made last week and back in December. Here is what I tried:

    1. Installed the latest Python version 3.13.3
    2. Tried to install the IfxPy package via python setup.py install. It failed to compile.
    3. I saw in the terminal output:
      Please avoid running ``setup.py`` directly.
      Instead, use pypa/build, pypa/installer or other
      standards-based tools.
    4. I then installed the build package via pip install build
    5. Next I executed python -m build and it also failed to compile.

    See attached terminal outputs.

    Thanks



    ------------------------------
    Malcom Terry
    ------------------------------

    Attachment(s)



  • 15.  RE: Cannot connect to Informix database via Python

    Posted 16 days ago

    Hi Malcolm,

    I was on annual leave last week, hence no reply.

    Unless HCL can understand and correct the error 'gcc' throws I can only look to reproduce your issue. To help me, I have an RPM spec file I use in Docker builder which works by running 'pip3 install ifxpy' then packaging all the files that result. It can be adapted to different Linux flavours, provided your distro uses RPM. Regardless it provides a scripted set up that works every time (for Rocky 8 and Python 3.6).

    Did you try 'pip3 install ifxpy' since HCL did the fix here? https://github.com/OpenInformix/IfxPy/commit/57b8a602e80fbd17a5e14485fc5fe2de64d5fec2

    What is your build environment - Linux flavour, version, steps taken to install newer Python release?

    Ben.



    ------------------------------
    Benjamin Thompson
    ------------------------------



  • 16.  RE: Cannot connect to Informix database via Python

    Posted 15 days ago

    Ben,

    I've tried various ways to build a new package using the updated Git repo, but no success. 

    I'm currently using a CentOS 10 VM and a CentOS 7.9 VM with virtual (pyenv) Python 3.8.

    Thanks,

    Malcom



    ------------------------------
    Malcom Terry
    ------------------------------



  • 17.  RE: Cannot connect to Informix database via Python

    Posted 13 days ago
    Edited by Javier Sagrera 13 days ago

    Hi Malcon,


    Would you mind to share the error you are getting in your system?

    I just tried on a fresh VM running CentOS 9 (GCC 11.5 and Python 3.9.21) and it builds fine directly from source. 

    There was a warning regarding SQLLEN vs SQLINTEGER for SQLRowCount() which need some fixing. Maybe on your platform the compiler is taking that as an error. 

    Regards,

    Javier 

    Thanks,

    Javier



    ------------------------------
    Javier Sagrera
    ------------------------------