On Wed, Aug 20, 2008 at 6:34 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
> On Aug 20, 2008, at 12:51 PM, Will Temperley wrote:
>
>>
>> Hi
>>
>> I'm having some trouble with a UTF8 DB and strings not being
>> converted. I get the following:
>>
>> 'ascii' codec can't encode character u'\xe2' in position 142: ordinal
>> not in range(128).
>>
>> See the code below. With the same engine, if I connect directly, I
>> have no problems but if I go via my mapped class (Source, also see
>> below), I get such errors.
>>
>> Any ideas? Am I just being dumb here?
>
>
> mapping looks fine.  The "convert_unicode=True" is not needed since
> this is implicit within the UnicodeText type, and in rare cases could
> even cause the problem you're having if you're storing binary data in
> other String columns.
>
> Would have to see what actual steps to take which cause the issue (is
> this during query(), during flush(), during lazyload, etc). as well as
> a stack trace.
>

Thanks for having a look.

It happens when I do this in a python shell - I'm just printing the __repr__:

Source.metadata.create_all(engine)
results = session.query(Source).all()
results

.<Lots of stuff from db> including An. hyrcanus, An. pseudopictus, and
An. nigerrimus, are reviewed., Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe2' in
position 142: ordinal not in range(128)

This is what happens when I put it into a Django template: (same error).

Original Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/template/debug.py",
line 71, in render_node
    result = node.render(context)
  File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py",
line 148, in render
    nodelist.append(node.render(context))
  File "/usr/lib/python2.5/site-packages/django/template/debug.py",
line 87, in render
    output = force_unicode(self.filter_expression.resolve(context))
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py",
line 542, in resolve
    new_obj = func(obj, *arg_vals)
  File "/usr/lib/python2.5/site-packages/django/template/defaultfilters.py",
line 31, in _dec
    args[0] = force_unicode(args[0])
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py",
line 51, in force_unicode
    s = unicode(str(s), encoding, errors)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe2' in
position 142: ordinal not in range(128)


Cheers

Will

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to