Page 1 of 1

print UnicodeEncodeError

Posted: Wed Jul 06, 2022 12:40 pm
by decompile
Hey!

I'm usually printing alot of informations to the console, to just know what's currently going. I've figured out that for some reason, I'm getting UnicodeEncodeErrors when printing player names with special characters, but its seems to be very random, because its fixed after restarting the whole machine and then prints the special characters as normal.

This is what the exception looks like:

Syntax: Select all

[SP] Caught an Exception:
print_console(f"IRC | {server_name} | {name} : {message}")
File "../addons/source-python/plugins/SurfTricks/libs/core/globals.py", line 1407, in print_console
print(message)

UnicodeEncodeError: 'ascii' codec can't encode characters in position 63-65: ordinal not in range(128)


I would probably need to encode and decode the names again, but is there a reason for this happening, since its working as intended for the most time?

Re: print UnicodeEncodeError

Posted: Wed Jul 06, 2022 4:39 pm
by L'In20Cible
My first guess would be that, at some point, your locale settings are being overwritten somehow causing SP to resolve to ascii after a subsequent launch of your server(s). We -could- enforce an encoding, however, this would likely result into weird behaviours for everything that rely on locale/default encoding. In fact, here is a test build that allow you to force the encoding of the standard streams through the following command line parameter:

Code: Select all

-sp_standard_stream_encoding utf-8


That said, using core.console_message instead of print would likely be enough to fix these issues. At least, in that specific context. I would recommend you debug your locale in any case, though.

Re: print UnicodeEncodeError

Posted: Wed Jul 06, 2022 10:26 pm
by decompile
Thank you for your update!

The machine where the exception occurs is running CS:S only, since your core file is inside a csgo folder.

Its a very weird behaviour, since the machine's output of /etc/default/locale is:
LANG=en_US.UTF-8

Re: print UnicodeEncodeError

Posted: Thu Jul 07, 2022 1:58 am
by L'In20Cible
decompile wrote:Thank you for your update!

The machine where the exception occurs is running CS:S only, since your core file is inside a csgo folder.

My bad, knew you were on Linux but thought this was for CS:GO. I will drop a CS:S build in that directory shortly.

decompile wrote:Its a very weird behaviour, since the machine's output of /etc/default/locale is:
LANG=en_US.UTF-8

Is this when it is working as intended? If so, what is it set to when you start encountering these errors?

Re: print UnicodeEncodeError

Posted: Mon Jul 25, 2022 2:09 pm
by decompile
Sorry for my late reply, i was on holidays!

I will update you as soon as this problem reoccurs.