我前段时间下载了cx_oracle并编写了一个脚本来将数据转换为XML。我不得不重新启动我的操作系统,并抓住了最新版本的cx_Oracle(5.0.3),突然间我的代码被破坏了。为什么cx_oracle execute()现在不像我的字符串?
第一件事是,cx_Oracle.connect想要unicode而不是字符串的用户名和密码,这是很容易修复。但是现在它在cursor.execute上保持失败,并告诉我即使type()告诉我它是一个字符串,我的字符串也不是一个字符串。
这是一个测试脚本,我初步使用了很久以前,在我的旧版本上运行良好,但现在不能在cx_Oracle上运行。
import cx_Oracle
ip = 'url.to.oracle'
port = 1521
SID = 'mysid'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
connection = cx_Oracle.connect(u'name', u'pass', dsn_tns)
cursor = connection.cursor()
cursor.arraysize = 50
sql = "select isbn, title_code from core_isbn where rownum<=20"
print type(sql)
cursor.execute(sql)
for isbn, title_code in cursor.fetchall():
print "Values from DB:", isbn, title_code
cursor.close()
connection.close()
当我跑,我得到:
回溯(最近最后一次通话): 文件 “C:\的NetBeansProjects \ Python中的\ src \ db_temp.py”,第48行,在 光标.execute(sql) TypeError:期望无或字符串
有谁知道我可能做错了什么?