I have bee trying to deal with an erratic error for the last 3 day. I
hope you can rescue me!!!

After experiencing erratic errors that appeared from time to time on a
larger project (i.e. ViewDoesNotExist) I have reduced my project to a
very simple application that runs on apache with mod_python and
connects to Oracle via cx_oracle (4.3).

after reloading apache I get the following error:

----
TemplateSyntaxError at /test/

Caught an exception while rendering: 'utf8' codec can't decode bytes
in position 3-4: invalid data. You passed in 'OTO\xd1O' (<type 'str'>)
...
----
After refreshing the browser page a few times the error disappears the
the template displays correctly (a list of words, some of which are in
spanish).  After that the error reappears form time to time.

I guess that the database is sending the data in a non UTF8 format
when the error appears, but I can not understand:

-  Why it happens sometimes and not always?
-  If it is a problem with oracle (or cx_oracle) why is it manifested
afer reloading apache?

PLEASE help me with any idea or suggestion!!

I am using
Redhat ES release 4 U7
Apache 2.0.52-41.ent.2
python 2.3
django1.0
mod_python 3.2.1
cx_oracle 4.4

These are my basic models/views/templates:

prueba1.models.py
-------------------------
from django.db import models

class PeriodosAcademicos(models.Model):
  peri_ccod= models.IntegerField(db_column='PERI_CCOD',
primary_key=True)
  peri_tdesc = models.CharField(max_length=100,
db_column='PERI_TDESC')
  class Meta:
    db_table = 'PERIODOS_ACADEMICOS'

prueba1.views.py
-----------------------
from prueba1.models import PeriodosAcademicos
from django.shortcuts import render_to_response

def test(request):
  periods = PeriodosAcademicos.objects.all()
  return render_to_response('test.html',{'periods':periods})

prueba1/templates/test.html
-------------------------------------
<h1>Test</h1>
{% for period in periods %}
<li>{{period.peri_tdesc}}
{% endfor %}

This is the full error transcript:
TemplateSyntaxError at /test/

Caught an exception while rendering: 'utf8' codec can't decode bytes
in position 3-4: invalid data. You passed in 'OTO\xd1O' (<type 'str'>)

Original Traceback (most recent call last):
  File "/usr/lib/python2.3/site-packages/django/template/debug.py",
line 71, in render_node
    result = node.render(context)
  File "/usr/lib/python2.3/site-packages/django/template/
defaulttags.py", line 123, in render
    len_values = len(values)
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 154, in __len__
    self._result_cache = list(self.iterator())
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 269, in iterator
    for row in self.query.results_iter():
  File "/usr/lib/python2.3/site-packages/django/db/models/sql/
query.py", line 206, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.3/site-packages/django/db/models/sql/
query.py", line 1714, in <lambda>
    result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
  File "/usr/lib/python2.3/site-packages/django/db/backends/oracle/
base.py", line 400, in fetchmany
    return tuple([tuple([to_unicode(e) for e in r]) for r in
Database.Cursor.fetchmany(self, size)])
  File "/usr/lib/python2.3/site-packages/django/db/backends/oracle/
base.py", line 411, in to_unicode
    return force_unicode(s)
  File "/usr/lib/python2.3/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
3-4: invalid data. You passed in 'OTO\xd1O' (<type 'str'>)

Request Method:         GET
Request URL:    http://172.16.110.42/test/
Exception Type:         TemplateSyntaxError
Exception Value:

Caught an exception while rendering: 'utf8' codec can't decode bytes
in position 3-4: invalid data. You passed in 'OTO\xd1O' (<type 'str'>)

Original Traceback (most recent call last):
  File "/usr/lib/python2.3/site-packages/django/template/debug.py",
line 71, in render_node
    result = node.render(context)
  File "/usr/lib/python2.3/site-packages/django/template/
defaulttags.py", line 123, in render
    len_values = len(values)
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 154, in __len__
    self._result_cache = list(self.iterator())
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 269, in iterator
    for row in self.query.results_iter():
  File "/usr/lib/python2.3/site-packages/django/db/models/sql/
query.py", line 206, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.3/site-packages/django/db/models/sql/
query.py", line 1714, in <lambda>
    result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
  File "/usr/lib/python2.3/site-packages/django/db/backends/oracle/
base.py", line 400, in fetchmany
    return tuple([tuple([to_unicode(e) for e in r]) for r in
Database.Cursor.fetchmany(self, size)])
  File "/usr/lib/python2.3/site-packages/django/db/backends/oracle/
base.py", line 411, in to_unicode
    return force_unicode(s)
  File "/usr/lib/python2.3/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
3-4: invalid data. You passed in 'OTO\xd1O' (<type 'str'>)

Exception Location:     /usr/lib/python2.3/site-packages/django/template/
debug.py in render_node, line 81
Python Executable:      /usr/bin/python
Python Version:         2.3.4
Python Path:    ['/var/www/html/tide', '/var/www/html/tide/
reportes_test', '/usr/lib/python23.zip', '/usr/lib/python2.3', '/usr/
lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk', '/usr/lib/
python2.3/lib-dynload', '/usr/lib/python2.3/site-packages']
Server time:    Wed, 18 Mar 2009 15:43:26 -0500

---------------
When it works, the page shows:
<h1>Test</h1>

<li>OTOÑO

<li>PRIMAVERA

<li>PRIMAVERA

<li>INVIERNO
...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to