home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.07k stars 29.73k forks source link

Rest integration uses a default UTF-8 encoding which is not the one of the REST API I want to use #85145

Closed cnico closed 1 year ago

cnico commented 1 year ago

The problem

I use REST integration to poll the REST API of a heater boiler (an okofen one) which exposes a simple JSON API directly on the IP address of the device which is in the same network as home assistant.

It works very well but I have a small encoding issue. The text is in french and they do not display correctly : "réduit" is displayed "r�duit" in home assistant.

When I display the Json in the browser, it displays correctly.

Using curl to get the raw content of the REST json, I found that it is encoded in ANSI or IS0-8859-1 and I suppose that by default home assistant decode with UTF-8.

Is it possible to correct this problem by adding an encoding parameter to the REST integration ? It could be optional with UTF-8 by default and a user defined value that would be ISO-8859-1 in my case.

What version of Home Assistant Core has the issue?

2022.12.9

What was the last working version of Home Assistant Core?

None

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

REST

Link to integration documentation on our website

https://www.home-assistant.io/integrations/rest/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

rest documentation rest source

cnico commented 1 year ago

For information, I use the exemple as this one and we can see in its printscreen the same problem : https://github.com/dominikamann/HomeAssistant-Oekofen-Pellematic-REST-Template

olivierouellet commented 1 year ago

Same problem as #75610. Please go there for more info. It's related to a change in httpx that happened in 2022.6 .

olivierouellet commented 1 year ago

If the PR is merged, you should be able to add character_encoding: ISO-8859-1 to your code and it should solve your problem.

rest:
  - resource: http://website.com/file.xml
    character_encoding: ISO-8859-1
epenet commented 1 year ago

Closed via #90254

olivierouellet commented 1 year ago

@cnico @bigcookie

Make sure to use encoding: ISO-8859-1 instead of character_encoding: ISO-8859-1 mentioned the other day. The labeling was changed during the PR process.