Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Help with UnicodeEncodeError

If you have a question or need help, this is the place to be.
Post Reply
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Help with UnicodeEncodeError

Post by Pako »

I have code:

Code: Select all

if radioBoxSource.GetSelection():
    arrayValue[4]=dynSizer.GetChildren()[1].GetWindow().GetValue()
else:
    arrayValue[5]=dynSizer.GetChildren()[1].GetWindow().GetValue()

Code: Select all

params='/slideshow="'+(arrayValue[4] if arrayValue[7] else arrayValue[5])+'" /ini="'+eg.APPDATA+'\\EventGhost\\"'
return win32api.ShellExecute(
    0, 
    None, 
    tail,
    params,
    head, 
    1
)
If arrayValue[4], arrayValue[5] or eg.APPDATA contains non-ASCII character, I get error:

Code: Select all

UnicodeEncodeError: 'ascii' codec can't encode character u'\u0161' in position 42: ordinal not in range(128)
I can't find solving.

Pako
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Help with UnicodeEncodeError

Post by Bitmonster »

Do you get an UnicodeError if you simply do:

Code: Select all

print eg.APPDATA
?
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Help with UnicodeEncodeError

Post by Pako »

Bitmonster wrote:Do you get an UnicodeError if you simply do: print eg.APPDATA?
No, it works errorless and print params too.
Pako
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Help with UnicodeEncodeError

Post by Bitmonster »

Normally you get an unicode error if you try to add normal strings that contains characters with an ordinal > 128. But you won't get an error, if these strings are unicode strings. So I guess your GetValue() doesn't return an unicode string (as it should) but a normal string. You can prove this if you try:
print type(dynSizer.GetChildren()[1].GetWindow().GetValue())
It will return <type 'str'> instead of <type 'unicode'> I suppose.
What type of control is it you are querying there? And from where has it gotten its value?
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Help with UnicodeEncodeError

Post by Bitmonster »

Here is a nice tutorial about unicode in Python:
http://boodebr.org/main/python/all-abou ... nd-unicode
It is big, but unicode is a complicated topic.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Help with UnicodeEncodeError

Post by Pako »

Bitmonster wrote: What type of control is it you are querying there? And from where has it gotten its value?
Return <type 'unicode'> and control is type and value gotten from eg.DirBrowseButton() and eg.FileBrowseButton().
Pako
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Help with UnicodeEncodeError

Post by Bitmonster »

Can you attach the full code here, so I can try it out?
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Help with UnicodeEncodeError

Post by Pako »

Already I have solving:

Code: Select all

import locale
myEncoding = locale.getdefaultlocale()[1]

return win32api.ShellExecute(
    0, 
    None, 
    tail,
    params.encode(myEncoding),
    head, 
    1
)
Thanks !
Pako
Post Reply