Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python连接到Oracle DB会导致cx_Oracle.DatabaseError:ORA-12547:TNS:失去联系_Python_Python 3.x_Oracle_Python 2.7_Oracle11g - Fatal编程技术网

使用python连接到Oracle DB会导致cx_Oracle.DatabaseError:ORA-12547:TNS:失去联系

使用python连接到Oracle DB会导致cx_Oracle.DatabaseError:ORA-12547:TNS:失去联系,python,python-3.x,oracle,python-2.7,oracle11g,Python,Python 3.x,Oracle,Python 2.7,Oracle11g,我正在使用python连接到我学校的OracleDB来执行一些查询 这些是我累了的台阶 1) pip install cx_Oracle. 2) Downloaded oracle instant client 12.2 for mac. 3) Moved the downloaded files to /usr/local/lib. 4) When I executed the below script, I get the following error. 注意:我可以使用SQLDevel

我正在使用python连接到我学校的OracleDB来执行一些查询

这些是我累了的台阶

1) pip install cx_Oracle.
2) Downloaded oracle instant client 12.2 for mac.
3) Moved the downloaded files to /usr/local/lib.
4) When I executed the below script, I get the following error.
注意:我可以使用SQLDeveloper连接到数据库,并手动执行SQL查询。仅在使用python脚本时,我得到以下错误

Traceback (most recent call last):
  File "oracle.py", line 30, in <module>
    db = DB()
  File "oracle.py", line 13, in __init__
    self.conn = cx_Oracle.connect(CONN_STR)
cx_Oracle.DatabaseError: ORA-12547: TNS:lost contact



import cx_Oracle
    CONN_INFO = {
        'host': 'xxxxxx@gmu.edu',
        'port':  1630,
        'user': 'username',
        'psw':  'password',
        'service': 'PORTALSRV'}

    CONN_STR = '{user}/{psw}@{host}:{port}/{service}'.format(**CONN_INFO)

    class DB:
        def __init__(self):
            self.conn = cx_Oracle.connect(CONN_STR)


    QUERY = '''
        SELECT
            *
        FROM
            EMPLOYEES
    '''

    def query(self, query, params=None):
            cursor = self.conn.cursor()
            result = cursor.execute(query, params).fetchall()
            cursor.close()
            return result


    db = DB()
    result = db.query(QUERY)

    print(result)
回溯(最近一次呼叫最后一次):
文件“oracle.py”,第30行,在
db=db()
文件“oracle.py”,第13行,在_init中__
self.conn=cx\u Oracle.connect(conn\u STR)
cx_Oracle.Database错误:ORA-12547:TNS:失去联系
导入cx_Oracle
连接信息={
'主机':'xxxxxx@gmu.edu',
“端口”:1630,
“用户”:“用户名”,
“psw”:“密码”,
“服务”:“PORTALSRV”}
CONN_STR='{user}/{psw}@{host}:{port}/{service}'。格式(**CONN_INFO)
DB类:
定义初始化(自):
self.conn=cx\u Oracle.connect(conn\u STR)
查询=“”
挑选
*
从…起
员工
'''
def查询(self、query、params=None):
cursor=self.conn.cursor()
结果=cursor.execute(查询,参数).fetchall()
cursor.close()
返回结果
db=db()
结果=db.query(查询)
打印(结果)