Форум сайта python.su
Есть код:
# -*- coding: cp1251 -*-
from sqlobject import *
class Person(SQLObject):
firstName = StringCol()
middleInitial = StringCol(length=1, default=None)
lastName = StringCol()
sqlhub.processConnection = connectionForURI('mssql://sa:passw@127.0.0.1/sqlobject')
Person.createTable()
p = Person(firstName="John", lastName="Doe")
p = Person(firstName='Вася', lastName='Пупкин', middleInitial="Q")
print "OK"
Traceback (most recent call last):
File "C:\Documents and Settings\user\workspace\1\src\pack\sqlobject_example.py", line 15, in <module>
p = Person(firstName='Вася', lastName='Пупкин', middleInitial="Q")
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\declarative.py", line 89, in _wrapper
return fn(self, *args, **kwargs)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 1183, in __init__
self._create(id, **kw)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 1220, in _create
self._SO_finishCreate(id)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 1247, in _SO_finishCreate
self._init(id)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 924, in _init
self._SO_selectInit(selectResults)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 1127, in _SO_selectInit
colValue = col.to_python(colValue, self._SO_validatorState)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\col.py", line 513, in to_python
return value.encode(dbEncoding)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
Офлайн
Использовать юникод.
Офлайн
FerromanПеределал на такой код.
Использовать юникод.
# -*- coding: utf-8 -*-
from sqlobject import *
class Person(SQLObject):
firstName = StringCol()
middleInitial = StringCol(length=1, default=None)
lastName = StringCol()
sqlhub.processConnection = connectionForURI('mssql://sa:pass@127.0.0.1/sqlobject')
fname = u"Вася"
lname = u"Пупкин"
cp_db = 'cp1251'
p = Person(firstName=fname.encode(cp_db), lastName=lname.encode(cp_db))
a = Person.get
Traceback (most recent call last):
File "C:\Documents and Settings\user\workspace\1\src\pack\sqlobject_example.py", line 19, in <module>
lastName=lname.encode(cp_db))
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\declarative.py", line 89, in _wrapper
return fn(self, *args, **kwargs)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 1183, in __init__
self._create(id, **kw)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 1220, in _create
self._SO_finishCreate(id)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 1247, in _SO_finishCreate
self._init(id)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 924, in _init
self._SO_selectInit(selectResults)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\main.py", line 1127, in _SO_selectInit
colValue = col.to_python(colValue, self._SO_validatorState)
File "c:\python25\lib\site-packages\SQLObject-0.10.0-py2.5.egg\sqlobject\col.py", line 513, in to_python
return value.encode(dbEncoding)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
Отредактировано (Авг. 12, 2008 10:24:33)
Офлайн
ответ запостил здесь
Офлайн