Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python connection oracle configuration

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Environment:

Operating system: win7 64 bit, CPU is the PC of inter

Oracle server: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production

Oracle local client: Release 11.2.0.1.0 32bit Production

Python version: python2.7.5 (installation path: C:\ Python27\)

Cx_Oracle version: cx_Oracle-5.2.1-11g.win-amd64-py2.7.exe

Iinstantclient version: instantclient-basic-win-x86-64-11.2.0.1.0.zip

In the process of learning python, you need to connect to the oracle database, so install cx_Oracle.

Install cx_Oracle-5.2.1-11g.winmuramd64murpy2.7.exedepartment import cx_Oracle to report an error. Hint: import cx_Oracle

ImportError: DLL load failed:% 1 is not a valid Win32 application. According to the error message, the dll file should be missing, because my native oracle client is 32-bit, and 64-bit cx_Oracle programs will definitely report errors when calling 32-bit dynamic libraries.

According to the article http://blog.csdn.net/huzhenwei/article/details/3946308, I went to oracle website to download instance client, the address is:

Http://www.oracle.com/technology/software/tech/oci/instantclient/index.html .

I downloaded the version of instantclient-basic-win-x86-64-11.2.0.1.0.zip.

Extract the C:\ instantclient_11_2 directory directly.

Add to the "system variables" of "Environment variables":

ORACLE_HOME = C:\ instantclient_11_2 (online says it is needed, but the test is OK without adding it)

TNS_ADMIN = C:\ instantclient_11_2 (online says it is needed, but the test is OK without adding it)

NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK

Modify the Path variable and add C:\ instantclient_11_2 after it

Then put the oci.dll file in the unzipped package under% python_home%\ Lib\ site-packages, and import will not make an error again.

Execute the test python footer this error, prompt cx_Oracle Interface Error: Unable to acquire Oracle enviroment handle. Start PLSQL login to open just now tns, but login error ORA-1 thought it was instance client and previously installed 32-bit oracle client conflict, ORA-12557. It feels like this 64-bit instance client conflicts with the 32-bit oracle client installed before. So delete the ORACLE_PATH in the environment variables and you can log in to PLSQL. But the test statement still reported that error. After tossing about for a long time, I finally became a doctor. I tried to copy all the dll files in C:\ instantclient_11_2 to the C:\ Python27\ Lib\ site-packages directory of python. I RUN again, but I didn't make a mistake. Then delete one by one, and finally found that oraociei11.dll deletion will report an error, while other dll delete re-Run will not report an error.

However, logging in with PLSQL will still report an error, so you have to delete the environment variable ORACLE_HOME, which does not affect the use of cx_Oracle. The principle is not very clear, write it down first.

Python test script:

#! / usr/bin/python#coding=utf-8import cx_Oracleusername = "smb" passwd = "czty_smb" host = "192.168.150.233" port = "1521" sid = "zsms" dsn = cx_Oracle.makedsn (host, port, sid) con = cx_Oracle.connect (username, passwd, dsn) cursor= con.cursor () sql = 'SELECT smbms Prtms FROM t_user_mobile_dz'cursor.execute (sql) result = cursor.fetchall () print "Total:" + str (cursor.rowcount) for row in result: print rowcursor.close () con.close ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report