cx_Oracle django and "dumb" connect

52 views
Skip to first unread message

Mike RA9FTM

unread,
Apr 5, 2009, 12:59:40 PM4/5/09
to Django users
Hi. I need direct connection to oracle for import some information
sometimes.
Here is what I do for first test:


def orcl_test(request):
connstr='scott/tiger@orcl'
conn = cx_Oracle.connect(connstr)
curs = conn.cursor()
curs.execute('select * from dept')
rows = [row[2] for row in curs.fetchall()]
conn.close()
return render_to_response('DekanatImport/test.html', {'rows':
rows})


This django view work, when I first load it in browser. But after
pressing F5 I have following error.
By debugging it using PyDev, I found, that it appears after conn =
cx_Oracle.connect(connstr) string.

I am using Django 1.0, cx_Oracle-5.0.1-10g.win32-py2.6.msi.

raceback (most recent call last):

File "I:\Python26\lib\site-packages\django\core\servers
\basehttp.py", line 277, in run
self.result = application(self.environ, self.start_response)

File "I:\Python26\lib\site-packages\django\core\servers
\basehttp.py", line 634, in __call__
return self.application(environ, start_response)

File "I:\Python26\lib\site-packages\django\core\handlers\wsgi.py",
line 239, in __call__
response = self.get_response(request)

File "I:\Python26\lib\site-packages\django\core\handlers\base.py",
line 128, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)

File "I:\Python26\lib\site-packages\django\core\handlers\base.py",
line 148, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)

File "I:\Python26\lib\site-packages\django\views\debug.py", line 39,
in technical_500_response
html = reporter.get_traceback_html()

File "I:\Python26\lib\site-packages\django\views\debug.py", line 97,
in get_traceback_html
'exception_value': smart_unicode(self.exc_value,
errors='replace'),

File "I:\Python26\lib\site-packages\django\utils\encoding.py", line
35, in smart_unicode
return force_unicode(s, encoding, strings_only, errors)

File "I:\Python26\lib\site-packages\django\utils\encoding.py", line
70, in force_unicode
raise DjangoUnicodeDecodeError(s, *e.args)

DjangoUnicodeDecodeError: 'utf8' codec can't decode bytes in position
11-12: invalid data. You passed in DatabaseError(<cx_Oracle._Error
object at 0x00D48E60>,) (<class 'cx_Oracle.DatabaseError'>)

Alex Gaynor

unread,
Apr 5, 2009, 1:02:28 PM4/5/09
to django...@googlegroups.com
Instead of importing cx_oracle directly you should do `from django.db import connection` which gets you a normal PEP-249 database cursor, but Django wraps a few of the methods to make it play nice with Unicode and such.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire
"The people's good is the highest law."--Cicero

Mike RA9FTM

unread,
Apr 5, 2009, 1:22:29 PM4/5/09
to Django users
Thank you for your answer.
I think it will be a problem, beacuse I am already using postgresql
database in my django project.

On 5 апр, 17:02, Alex Gaynor <alex.gay...@gmail.com> wrote:
>
> Instead of importing cx_oracle directly you should do `from django.db import
> connection` which gets you a normal PEP-249 database cursor, but Django
> wraps a few of the methods to make it play nice with Unicode and such.

But, how I tried to resolve my problem:

By googling found and added this one:
import os
os.environ["NLS_LANG"] = "Russian_Russia.UTF8"

So, there is no message about unicode decode problems, but I get
oracle error "ORA-12638".
Again, by googling I found how to resolve this:
comment out string SQLNET.AUTHENTICATION_SERVICES in file sqlnet.ora.

Now it is working, but I think it is bad way.
So, will try to learn this http://code.djangoproject.com/wiki/MultipleDatabaseSupport
Reply all
Reply to author
Forward
0 new messages