print UnicodeEncodeError

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

print UnicodeEncodeError

Postby decompile » Wed Jul 06, 2022 12:40 pm

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?
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: print UnicodeEncodeError

Postby L'In20Cible » Wed Jul 06, 2022 4:39 pm

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.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: print UnicodeEncodeError

Postby decompile » Wed Jul 06, 2022 10:26 pm

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
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: print UnicodeEncodeError

Postby L'In20Cible » Thu Jul 07, 2022 1:58 am

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?
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: print UnicodeEncodeError

Postby decompile » Mon Jul 25, 2022 2:09 pm

Sorry for my late reply, i was on holidays!

I will update you as soon as this problem reoccurs.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 20 guests