robmarkcole / HASS-plate-recognizer

Read number plates with https://platerecognizer.com/
135 stars 29 forks source link

Update for image_processing.platerecognizer_doorbell_main_proxy fails #69

Open totalitarian opened 2 years ago

totalitarian commented 2 years ago

Any idea what would cause this?

This error originated from a custom integration.

Logger: homeassistant.helpers.entity
Source: custom_components/platerecognizer/image_processing.py:224
Integration: platerecognizer (documentation)
First occurred: 16 November 2022 at 21:27:27 (884 occurrences)
Last logged: 16:02:06

Update for image_processing.platerecognizer_doorbell_main_proxy fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/site-packages/simplejson/decoder.py", line 373, in decode
    raise JSONDecodeError("Extra data", s, end, len(s))
simplejson.errors.JSONDecodeError: Extra data: line 1 column 4 - line 1 column 15 (char 3 - 14)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/platerecognizer/image_processing.py", line 206, in process_image
    ).json()
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Extra data: line 1 column 4 (char 3)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 527, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 722, in async_device_update
    raise exc
  File "/usr/src/homeassistant/homeassistant/components/image_processing/__init__.py", line 163, in async_update
    await self.async_process_image(image.content)
  File "/usr/src/homeassistant/homeassistant/components/image_processing/__init__.py", line 144, in async_process_image
    return await self.hass.async_add_executor_job(self.process_image, image)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/platerecognizer/image_processing.py", line 224, in process_image
    _LOGGER.error(f"platerecognizer api response: {response}")
UnboundLocalError: local variable 'response' referenced before assignment

This is my config

  - platform: platerecognizer
    api_token: xxxxxxx
    regions:
      - gb
    save_file_folder: /config/images/platerecognizer/
    save_timestamped_file: True
    always_save_latest_file: True
    watched_plates:
      - xx67xxx
    mmc: True
    detection_rule: strict
    region: strict
    server: https://myhostname.com/v1/plate-reader/
    source:
      - entity_id: camera.doorbell_main_proxy
robmarkcole commented 2 years ago

This will occur if the server returns no response at https://github.com/robmarkcole/HASS-plate-recognizer/blob/b9f0998961c86a5052e51bb136ecbc4747eb861f/custom_components/platerecognizer/image_processing.py#L201

This is not well handled

totalitarian commented 2 years ago

Thanks but which server?

totalitarian commented 2 years ago

Oh I get it now, you only need that for paid account. Simplified my config and now it works :)