REST sensor utf8 problem

I am trying to configure a REST sensor for glances, (GPU temp) which isn’t part of the integration yet.

  - platform: rest
    name: "gpu0_temp"
    resource: http://glancesserver:61208/api/3/gpu/gpu_id/0
    method: GET
    headers:
      Content-Type: application/json
    value_template: '{{ value_json[0].temperature }}'

however it never sets up correctly with this error.

2020-11-21 22:26:02 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up rest platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/src/homeassistant/homeassistant/components/rest/sensor.py", line 116, in async_setup_platform
    await rest.async_update()
  File "/usr/src/homeassistant/homeassistant/components/rest/data.py", line 60, in async_update
    self.data = response.text
  File "/usr/local/lib/python3.8/site-packages/httpx/_models.py", line 1016, in text
    self._text = "".join([decoder.decode(self.content), decoder.flush()])
  File "/usr/local/lib/python3.8/site-packages/httpx/_decoders.py", line 204, in decode
    return self.decoder.decode(data)
  File "/usr/local/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9c in position 1: invalid start byte

however crul -v gives me this output

*   Trying 192.168.100.2...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x555e3299fdc0)
* Connected to hal (192.168.100.2) port 61208 (#0)
> GET /api/3/gpu/gpu_id/0 HTTP/1.1
> Host: hal:61208
> User-Agent: curl/7.64.0
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Sun, 22 Nov 2020 03:31:04 GMT
< Server: WSGIServer/0.2 CPython/3.8.2
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS
< Access-Control-Allow-Headers: Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token
< Content-Type: application/json; charset=utf-8
< Content-Encoding: identity
< Content-Length: 127
< 
* Closing connection 0
{"0": [{"key": "gpu_id", "gpu_id": 0, "name": "GeForce GTX 1050 Ti", "mem": 24.475394614670382, "proc": 2, "temperature": 58}]}

As work around I am getting this in node-red and parsing the JSON response, I think I am missing some header I cant seem to figure it out… any help!?

Figured it out …

needed to add for glances v3

    headers:
      Accept-encoding: gzip
1 Like