UnicodeEncodeError: 'charmap' codec can't encode character u'\u0218' in position 0: character maps to <undefined>

157 views
Skip to first unread message

Zoltán Bege

unread,
Mar 25, 2016, 5:12:27 AM3/25/16
to Django users
Hi,

I have a Django application where I have to update some personal data in a Firebird 2.5 DB with cp1250 encoding.
Yesterday I got some Internal Server Error while updating a person's first or last name when using Ș, ș, Ț, ț characters.

The error can be easily reproduced in python (2.7 and 3.4) shell:
>>> u'Ș'.encode('cp1250')
UnicodeEncodeError: 'charmap' codec can't encode character u'\u0218' in position 0: character maps to <undefined>

How I can encode the mentioned characters in cp1250 to avoid this error? I must use the Firebird 2.5 with cp1250 encoding, so db change is not an option.

Thanks,
Zoltan

Michal Petrucha

unread,
Mar 25, 2016, 5:48:40 AM3/25/16
to django...@googlegroups.com
The four characters you listed above do not have a representation in
CP-1250. However, CP-1250 does have similar characters: "Ş", "ş", "Ţ",
and "ţ". They look similar, but they are not the same – yours are
letters with a comma underneath, and the ones supported by CP-1250
have a cedilla.

What you could do is use str.translate, or just four str.replace calls
to replace those wrong characters with ones supported in CP-1250.

Good luck,

Michal
signature.asc

Zoltán Bege

unread,
Mar 25, 2016, 8:36:03 AM3/25/16
to django...@googlegroups.com
Thank you, Michal


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/5PusaQjQfWA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20160325094719.GD25061%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages