SQLAlchemy集成cx_Oracle中文乱码
问题描述
使用SQLAlchemy集成cx_Oracle后查出的中文数据都是???(也就是说乱码了)
解决方案
方案一(推荐)
注意SQLAlchemy的版本,此方案需要在1.3以上版本才有效!
create_conf = "oracle://{user}:{passwd}@{host}:{port}/{db}?encoding=UTF-8&nencoding=UTF-8"
_engine = create_engine(create_conf.format(**self.conf), encoding='utf-8')
方案二 (网上大多数解决方案)
import os
create_conf = "oracle://{user}:{passwd}@{host}:{port}/{db}"
_engine = create_engine(create_conf.format(**self.conf), encoding='utf-8')
os.environ["NLS_LANG"] = "GERMAN_GERMANY.UTF8"