emcniece / ha_imap_attachment

Home Assistant IMAP Attachment Component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Unable to serialize to JSON. Bad data found at [...]

swanitzek opened this issue · comments

I installed this custom integration by following the instructions. After adding the sensor to configuration.yaml Home Assistant won't start any longer. It stucks at "Loading data" and never redirects to the dashboard view.

  - platform: imap_attachment
    name: Kamera E-Mail
    server: <removed>
    port: 993
    username: <removed>
    password: <removed>
    senders:
      - <removed>
      - <removed>

The logfile contains the following error message related to the ha_imap_attachment custom integration:

2022-01-25 21:55:48 WARNING (Recorder) [homeassistant.components.recorder] State is not JSON serializable: <state sensor.kamera_e_mail=; from=REMOVED subject=, date=Tue, 25 Jan 2022 00:18:58 +0100 (CET), body=[<email.message.Message object at 0xb0158148>], num_attachments=0, attachment_paths=[], friendly_name=Kamera E-Mail @ 2022-01-25T21:55:28.060950+01:00>
2022-01-25 21:55:51 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.result[10](State: sensor.kamera_e_mail).attributes.body[0]=Content-Type: image/jpeg;
name="01_20220125001853000.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="01_20220125001853000.jpg"

/9j/2wCEABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19i
Z2hnPk1xeXBkeFxlZ2MBERISGBUYLxoaL2NCOEJjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2Nj
Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY//AABEIAfgDgAMBIgACEQEDEQH/xAGiAAABBQEBAQEBAQAA
AAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGh
CCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hp
anN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV
[...]

After removing the entries from configuration.yaml Home Assistant will start again.

Any suggestions?

HA-Version: 2021.11.5

Looks like plugin state needs to be serializable by json and something is failing in that process. Plugin state is defined at return self._message so HA is (somewhere internal) doing the equivalent of json.loads(self._message).

This plugin did work at one point, so either the serialization of state is new (and this plugin is broken for everyone) or the email message itself can't be serialized. I haven't tested this plugin for a while so I'm not sure which scenario is the issue.

You could try debugging down in the update() method - try dumping the entire message variable, or try json.loads(message) yourself and see if it errors. If this does fail, perhaps the update() method needs to handle a new scenario where attachments aren't serializable.

I see $.result[10] in your logs - how many attachments are in the email? You might also try a simpler email attachment like a text file instead of a picture. I wonder if the base64-encoded image is the issue...

I didn't get the remote debugger to work with my home assistant instance yet. This is definitively a thing I will try again.

The e-mails just have one attachment. A JPEG sent from a surveillance camera.

I will also try to sent a attachment with a simpler file format (textfile) as suggested. As soon as I know anything new I will post it here.