简体   繁体   English

python cx oracle期望字符串,unicode或缓冲区对象

[英]python cx oracle expecting string, unicode or buffer object

I am trying to run following code snippet in python to connect to oracle, but constantly running into following error. 我试图在python中运行以下代码段以连接到oracle,但是经常遇到以下错误。 I have tried a lot of combinations but it doesn't seem to work. 我尝试了很多组合,但似乎不起作用。 I understand the error, but don't understand what is incompatible here. 我了解该错误,但不了解这里有什么不兼容的地方。 Has anyone come across this issue? 有人遇到过这个问题吗? How do I fix it? 我如何解决它?

File "", line 1, in File "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1613, in execute 在执行中的文件“ /workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/engine/base.py”中的文件“”,行1,第1613行

connection = self.contextual_connect(close_with_result=True)   File   "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1661, in contextual_connect  

self.pool.connect(),   File "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/pool.py", line 326, in connect  

return _ConnectionFairy(self).checkout()   File   "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/pool.py", line 485, in __init__  

rec = self._connection_record = pool._do_get()   File   "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/pool.py", line 770, in _do_get  

return self._create_connection()   File   "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/pool.py", line 279, in _create_connection  

return _ConnectionRecord(self)   File   "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/pool.py", line 372, in __init__   

self.connection = self.__connect()   File   "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/pool.py", line 433, in __connect  

connection = self.__pool._creator()   File    "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 80, in connect

return dialect.connect(*cargs, **cparams)   File   "/workplace/applications/python2.7/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 283, in connect

return self.dbapi.connect(*cargs, **cparams)    

TypeError: expecting string, unicode or buffer object


from sqlalchemy.ext.declarative import declarative_base;
from sqlalchemy import create_engine;
engine = create_engine(u'oracle+cx_oracle://localhost:1521/orcl', echo=True)
result = engine.execute(u"select 1 from dual");

Setup: 设定:

Python 2.7 Python 2.7
SqlAlchemy 0.9.7 and 0.8.7 SqlAlchemy 0.9.7和0.8.7
Cx Oracle (latest version) Cx Oracle(最新版本)
Oracle Database 10g Release 10.2.0.2.0 Oracle数据库10g版本10.2.0.2.0

If you are running into this problem, most likely the cause is that you are not passing in arguments required by the underlying dbapi call. 如果您遇到此问题,则最有可能的原因是您没有传递基础dbapi调用所需的参数。

In my case I added additional arguments of user, password and dsn to the create_engine call along with existing ones, which got passed to cx_oracle call and it worked. 在我的情况下,我将用户,密码和dsn的其他参数与现有参数一起添加到create_engine调用中,这些参数传递给cx_oracle调用并且可以使用。

something like this should work 这样的事情应该工作

create_engine(u'oracle+cx_oracle://localhost:1521/orcl', echo=True, user='<>', password='<>', dsn='<>')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python cx_oracle 错误:需要字符串或字节 object - Python cx_oracle error: expecting string or bytes object 使用Pandas将SQL写入Oracle时出错:TypeError:需要字符串,unicode或缓冲区对象 - Error when using Pandas to write SQL to Oracle: TypeError: expecting string, unicode or buffer object cx_Oracle - “期望 None 或字符串” - cx_Oracle - "expecting None or a string" cx_Oracle.STRING到Python字符串转换 - cx_Oracle.STRING to Python string conversion Python 数据库连接:值错误:<cx_Oracle.LOB object at 0x000001CB4819E5A0> 不是 unicode 或序列 - Python DB Connection: ValueError: <cx_Oracle.LOB object at 0x000001CB4819E5A0> is not unicode or sequence 写入 Oracle:TypeError:期望字符串或字节 object - Writing to Oracle: TypeError: expecting string or bytes object 使用 Python 将 excel 表输入到 Oracle 中的表中 - 类型错误:期望字符串或字节 ZA8CFDE6331B4BEB69 - Input a excel sheet into a table in Oracle using Python - TypeError: expecting string or bytes object 通过Python SQLAlchemy cx_Oracle将带有“ \\ n”的Unicode文本保存到Oracle DB - Saving a Unicode Text with “\n” to Oracle DB via Python SQLAlchemy cx_Oracle 尝试在python 2.7 TypeError中删除Unicode特殊字符时出错:预期为字符串或其他字符缓冲区对象 - Error while try to remove Unicode special character in python 2.7 TypeError: expected a string or other character buffer object python-cx_Oracle是否允许您将所有列强制为cx_Oracle.STRING? - python - does cx_Oracle allow you to force all columns to be cx_Oracle.STRING?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM