Another COM question

Alex Martelli aleaxit at yahoo.com
Sun Apr 8 03:11:24 EDT 2001


"Volucris" <volucris at hotmail.com> wrote in message
news:3ad001dd$0$837$6e49188b at news.goldengate.net...
    [snip]
> I get the following error when I call my Python COM object though VB:
>
> Unexpected Python Error: exceptions.UnicodeError: ASCII encoding error:
> ordinal not in range(128)
    [snip]
> Does this have something to do with COM dealing in Unicode? Or what?

Exactly: your Python code is giving a Unicode object to a function expecting
a string, and the implicit Unicode->string conversion uses ASCII encoding
(so it can only handle characters whose ordinals are below 128).  You may
use an explicit call to the x.encode() method of a Unicode object x to get
as the result the encoded string; you may pass as an argument the name
of your preferred encoding ('iso-8859-1' is quite popular in Western Europe,
for example).  Haven't examined your code in detail, but I think you need
to do a
    data = data.encode('iso-8859-1')
at the start of your method.


Alex






More information about the Python-list mailing list