Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging (self.log) does not properly handle encoding of some non-English characters. #1895

Open
Aephir opened this issue Dec 11, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Aephir
Copy link

Aephir commented Dec 11, 2023

What happened?

The AppDaemon logger does not correctly log the non-English characters æ, ø, and å.

self.log("æøå")

logs:

2023-12-11 15:42:17.591901 INFO test: ������

There is a long version as well, as I found this when parsing data from an HTTP request. Here, I can see the a bit more of the character encoding, etc., but I'm not sure if that part is necessary. If so, find it by expanding the details below.

Logging a retrieved http request (with requests and json imported):

response = requests.get(url, headers=headers)
self.log(response.text)

logs the response, with characters that elsewhere are displayed correctly as ø here shown as \u00f8.

If I use json.loads:

response = requests.get(url, headers=headers)
product_info = json.loads(response.text)
self.log(product_info)

It displays the ø as ��. But it looks like it's only a logging issue, as:

response = requests.get(url, headers=headers)
product_info = json.loads(response.text)
weird_encoding = product_info['location']['name']  # access the string with an 'ø'
self.log(weird_encoding)
self.log("ø" in weird_encoding)

logs:

2023-12-11 15:25:11.935265 INFO test: K��kkenskab
2023-12-11 15:25:11.935895 INFO test: True

Version

4.4.2

Installation type

Home Assistant add-on

Relevant log output

The addon does not log the version of AppDaemon, only the version of HA, HA-OS and the Addon.

For AppDaemon it simply shows using AppDaemon 4.x.

Logs:

-----------------------------------------------------------
 Add-on: AppDaemon
 Python Apps and Dashboard using AppDaemon 4.x for Home Assistant
-----------------------------------------------------------
 Add-on version: 0.16.0
 You are running the latest version of this add-on.
 System: Home Assistant OS 11.2  (amd64 / qemux86-64)
 Home Assistant Core: 2023.12.1
 Home Assistant Supervisor: 2023.11.6
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.

From the addon github repo (https://github.com/hassio-addons/addon-appdaemon/tree/main/appdaemon) I'd guess it's AppDaemon v4.4.2.

Relevant code in the app or config file that caused the issue

No response

Anything else?

No response

@Aephir Aephir added the bug Something isn't working label Dec 11, 2023
@andreid1303
Copy link

andreid1303 commented Jan 19, 2024

I have this bug too. AppDaemon v4.4.2 in Python 3.11 virtual environment. I have checked that sys.stdout.encoding is UTF-8, app is written using VS Code in UTF-8. Same code prints correctly if I run it in python.

It can be solved with optional argument ascii_encode for log which is True by default and for UTF-8 it should be False:
self.log("æøå", ascii_encode=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants