python - mongoengine django and encoding, 'utf8' codec can't decode byte -
my mongodb use utf-8, , django read data not unicode, perhaps answer,but how solve problem?
the data in mongodb have chinese. if use other table totally of letters or numbers ,it works well.
class source(document) : id = intfield() url = stringfield() fetchtime = stringfield() domain = stringfield() xml_tpl_old = stringfield() xml_tpl_new = stringfield() source = binaryfield() xmlresult = stringfield() xmlresult1 = stringfield()
if use table of source( have chinese data )
source.objects.all()
the django give messages
traceback (most recent call last): file "e:/django_project/mysite/mysite/test.py", line 49, in unicode(source.objects) file "d:\python27\lib\site-packages\mongoengine-0.8.0rc4-py2.7.egg\mongoengine\queryset\queryset.py", line 216, in __repr__ self._populate_cache() file "d:\python27\lib\site-packages\mongoengine-0.8.0rc4-py2.7.egg\mongoengine\queryset\queryset.py", line 167, in _populate_cache self._result_cache.append(self.next()) file "d:\python27\lib\site-packages\mongoengine-0.8.0rc4-py2.7.egg\mongoengine\queryset\queryset.py", line 1148, in next raw_doc = self._cursor.next() file "d:\python27\lib\site-packages\pymongo-2.5-py2.7-win32.egg\pymongo\cursor.py", line 814, in next file "d:\python27\lib\site-packages\pymongo-2.5-py2.7-win32.egg\pymongo\cursor.py", line 763, in _refresh file "d:\python27\lib\site-packages\pymongo-2.5-py2.7-win32.egg\pymongo\cursor.py", line 720, in __send_message file "d:\python27\lib\site-packages\pymongo-2.5-py2.7-win32.egg\pymongo\helpers.py", line 106, in _unpack_response unicodedecodeerror: 'utf8' codec can't decode byte 0xa1 in position 74: invalid start byte
thanks!
try in python console
>>>import sys >>>sys.getdefaultencoding()
if result 'ascii',you should change default encoding.
Comments
Post a Comment