Thursday, July 1, 2010

UnicodeDecodeError: 'utf8' codec can't decode

Hi,

I am using a postgres database and DJango. I have a http url in my
database which contains some special characters, but a table query
returns the result successfully.

select http_url from mytable limit 1;
http_url
----------------------------------------
http://östrogenfrei.de/verhuetung.html


If I use Django model way to get the same data, I get following error
-
>>> from util import *
>>> cursor = connection.cursor()
>>> query="select http_url from cfedr_raw_data_20100526_24860_1277981101 where http_url like '%rogenfrei%'"
>>> cursor.execute(query)
>>> data = []
>>> for item in cursor.fetchall():
... print item
... data.append(item)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/firstpool/yjoshi/permanent/starbi/python2.6.1/lib/python2.6/
encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 7-10:
invalid data

Can anyone please throw some light on this? why is this occurring?
what is the solution.

Thanks in advance,

Yateen..

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment