0

I am trying to run following code snippet in python to connect to oracle, but constantly running into following error. 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

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
SqlAlchemy 0.9.7 and 0.8.7
Cx Oracle (latest version)
Oracle Database 10g Release 10.2.0.2.0

3
  • Did you try to remove the u (unicode) from the connection string ? Commented Aug 11, 2014 at 8:22
  • yes It didn't make a difference. Commented Aug 11, 2014 at 8:32
  • this actually disappeared after I added arguments required in cx_oracle constructor to create_engine as **kwargs which get passed to underlying cx_oracle call transparently. It was lacking those. Commented Aug 16, 2014 at 7:25

1 Answer 1

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.

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.

something like this should work

create_engine(u'oracle+cx_oracle://localhost:1521/orcl', echo=True, user='<>', password='<>', dsn='<>')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.