简体   繁体   中英

Python Database connection for informix DB using sqlalchemy

I'm trying to connect to remote informix DB as follows using python3 sqlalchemy but it fails to connect

sqlalchemy.create_engine("informix://usr1:pwd1@XXX:23300/DB_NAME;SERVER=dsinfmx").connect()

I get the below ERROR while connecting.

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:informix

Can someone please provide some help on this.. From Dbeaver, DB server is accessible.

I assume you are using Informix Python drivers. If not please install Informix Python driver ie IfxPy. Details to install Informix Python drivers are at this link https://github.com/OpenInformix/IfxPy/blob/master/README.md

Try out below code.

from sqlalchemy import create_engine
from sqlalchemy.dialects import registry
from sqlalchemy.orm import sessionmaker

registry.register("informix",        "IfxAlchemy.IfxPy", "IfxDialect_IfxPy")
registry.register("informix.IfxPy",  "IfxAlchemy.IfxPy", "IfxDialect_IfxPy")
registry.register("informix.pyodbc", "IfxAlchemy.pyodbc", "IfxDialect_pyodbc")

from sqlalchemy import Table, Column, Integer

ConStr = 'informix://<username>:<password>@<machine name>:<port number>/<database name>;SERVER=<server name>'
engine = create_engine(ConStr)
connection = engine.connect()

connection.close()
print( "Done2" )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM