1. 程式人生 > >20180125 Python flask+oracle遇到的問題和處理方案

20180125 Python flask+oracle遇到的問題和處理方案

這兩天搗鼓python的flask框架遇到點問題,以及相關處理方案,以此記錄。

1.連線oracle,出現cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: “
解決辦法: 參照 https://oracle.github.io/odpi/doc/installation.html#windows

1.Download an Oracle 11.2, 12.1 or 12.2 “Basic” or “Basic Light” zip file: 64-bit or 32-bit, matching your application architecture.
2.
Unzip the package into a single directory that is accessible to your application, for example C:\oracle\instantclient_12_2. 3.Set the environment variable PATH to include the path that you created in step 2. For example, on Windows 7, update PATH in Control Panel -> System -> Advanced System Settings
-> Advanced -> Environment Variables -> System Variables -> PATH.
4.If you intend to co-locate optional Oracle configuration files such as tnsnames.ora, sqlnet.ora or oraaccess.xml with Instant Client, then create a network\admin subdirectory, for example C:\oracle\instantclient_12_2\network\admin. This is the
default Oracle configuration directory for applications linked with this Instant Client. Alternatively, Oracle configuration files can be put in another, accessible directory. Then set the environment variable TNS_ADMIN to that directory name.

2.python oracle查詢中文亂碼(問號)問題
解決方案:
用的是sqlalchemy,在測試機器上部署查詢中文為”?”,簡單設定如下:

# -*- coding: utf-8 -*-  
import os   
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'