Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3255527
  • 博文数量: 815
  • 博客积分: 12898
  • 博客等级: 上将
  • 技术积分: 7883
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-25 09:57
文章分类

全部博文(815)

文章存档

2014年(1)

2011年(46)

2010年(192)

2009年(121)

2008年(70)

2007年(385)

分类: DB2/Informix

2010-08-05 22:42:50

  1. [atyu30@ns138 mediawiki]$ python
  2. Python 2.4.3 (#1, Jun 11 2009, 14:09:37)
  3. [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import cx_Oracle
  6. >>> db = cx_Oracle.connect('atyu30','atyu30','10.0.20.47:1521/YUYIZHI')
  7. Traceback (most recent call last):
  8.   File "", line 1, in ?
  9. TypeError: argument 1 must be unicode, not str
  10. >>> db1 = cx_Oracle.connect('atyu30/atyu30@10.0.20.47:1521/YUYIZHI')
  11. Traceback (most recent call last):
  12.   File "", line 1, in ?
  13. TypeError: argument 1 must be unicode, not str
同样的方式在windows下操作就没问题
  1. Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32
  2. Type "copyright", "credits" or "license()" for more information.
  3. >>> import cx_Oracle
  4. >>> conn = cx_Oracle.connect('atyu30','atyu30','10.0.20.47:1521/YUYIZHI')
  5. >>>

  6. >>> cursor = conn.cursor()
  7. >>> cursor.execute("""create table python_oracle(id number,name varchar2(50),password varchar(50),primary key(id))""")
  8. >>> cursor.execute("""insert into python_oracle values(1,'admin','password')""")
正确方法:
  1. [oracle@storage ~]$ python
  2. Python 2.4.3 (#1, Jun 11 2009, 14:09:37)
  3. [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import cx_Oracle
  6. >>> db = cx_Oracle.connect("atyu30/atyu30@//10.0.20.47/YUYIZHI")
  7. >>>
阅读(3708) | 评论(1) | 转发(0) |
0

上一篇:Python操作Oracle--环境安装

下一篇:Wikidbase

给主人留下些什么吧!~~

chinaunix网友2010-08-07 03:08:54

问题得以解决: 问题1。之前在oracle服务器中用oracle用户可以正常使用python操作oracle,用root用户却不可以 解决方法: 将oracle用户的环境变量赋给root用户即可 例如: [root@storage ~]# vi .bash_profile export ORACLE_BASE=/opt/oracle export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 export ORACLE_SID=atyu30 export ORACLE_TERM=xterm export PATH=/usr/sbin:$PATH export PATH=$ORACLE_HOME/bin:$PATH #export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:/usr/lib:/usr/local/lib export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib64:/usr/lib64:/usr/local