python调用oracle

2024-07-26  本文已影响0人  tivon_lee

访问 Oracle Instant Client 下载页面Oracle Instant Client Downloads,下载以下文件:Basic Package: 包含基本的库,解压下载的文件到一个目录oracle-instantclient

在终端中运行以下命令(加入path也可以):
export DYLD_LIBRARY_PATH=/Users///oracle-instantclient

终端运行pip install cx_Oracle

import cx_Oracle
connection = None
try:
    connection = cx_Oracle.connect(
        user='ISPDC',
        password='CONTI',
        dsn='127.0.0.1:1521/DBSABS06'
    )
    print("Connection successful")
except cx_Oracle.DatabaseError as e:
    print("Database connection error:", e)
finally:
    if connection:
        connection.close()

ORA-24454: client host name is not set
终端输入hostname,获取返回结果,然后编辑hosts文件,输入"127.0.0.1"对应hostname返回的结果,就可以了

上一篇 下一篇

猜你喜欢

热点阅读