鱼C论坛

 找回密码
 立即注册
查看: 2291|回复: 3

cx_Oracle链接报错

[复制链接]
发表于 2017-10-25 10:46:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本人菜鸟,请教大神如下问题,
-------------------------------------------
代码如下:
# -*- coding: utf-8 -*-

import cx_Oracle
import os

os.environ["NLS_LANG"] = 'SIMPLIFIED CHINESE_CHINA.UTF-8'
#os.environ['NLS_LANG'] = 'MERICAN_AMERICA.AL32UTF8'
conn = cx_Oracle.connect('test1/test1@132.161.10.12:1521/ORCL')

'''
aa = 'select * from ZS_A_BLEV'

cursor = conn.cursor()
cursor.execute(aa)
result = cursor.fetchall()
print (cursor.rowcount)         
for row in result:
    print(row)
cursor.close()
'''
-------------------------------------
报销信息如下:
Traceback (most recent call last):
  File "C:\Python36\cs.py", line 9, in <module>
    conn = cx_Oracle.connect('test1/test123@172.16.100.102:1521/ORCL',encode='utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 82-83: invalid continuation byte

-----------------------------------------
备注:
1、我本地是WIN10系统。
2、select userenv('language') from dual;   数据查询结果是:select userenv('language') from dual;
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-10-25 11:54:35 | 显示全部楼层
目测字符编码问题,试试去掉编码看看
'''''
连接数据库 oracle
'''  
import cx_Oracle  as db  
#  
username = "xx_ss"  
passwd = "xx"  
host = "192.168.176.122"  
port = "1521"  
sid = "orcl"  
dsn = db.makedsn(host, port, sid);  
con=db.connect (username,passwd,dsn)  
cursor = con.cursor()  
sql='select * from T_USER'  
cursor.execute (sql)  
result = cursor.fetchall()  
print("Total: " + str(cursor.rowcount))  
  
for row in result:  
       print  (row)  
cursor.close()  
con.close()  
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-25 13:28:35 | 显示全部楼层
感谢进行解答。

再说问题:
我这么改了后,报的错和上面还是一样。

问题就在如下行.
con=db.connect (username,passwd,dsn)

补充说明:我本地机子链接服务数据库用的plsql或dbvis,我想问一下,这些工具能链接,用cx_oracle时,本地机子还用装oracle的客户端吗?

谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-25 13:32:15 | 显示全部楼层
补充一下。
我机子是win10是64位,python是32位,cx_oracle是32位的。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-25 13:38

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表