ljmerza / frigate_plate_recognizer

Identify license plates via Plate Recognizer and add them as sublabels to Frigate
106 stars 13 forks source link

Some error messages are not logged. #55

Open miguelangel-nubla opened 3 months ago

miguelangel-nubla commented 3 months ago

I was having issues with the container restarting automatically whenever a license plate was being processed. Logs in /config/frigate_plate_recognizer.log:

2024-04-12 17:43:36,743 - __main__ - DEBUG - Getting snapshot for event: 1712942357.637452-fh7lyj, Crop: True
2024-04-12 17:43:36,743 - __main__ - DEBUG - event URL: http://frigate.local:5000/api/events/1712942357.637452-fh7lyj/snapshot.jpg
2024-04-12 17:43:38,688 - __main__ - INFO - Time: 2024-04-12 17:43:38.688
2024-04-12 17:43:38,688 - __main__ - INFO - Python Version: 3.9.19 (main, Mar 20 2024, 20:37:44)
[GCC 12.2.0]
2024-04-12 17:43:38,688 - __main__ - INFO - Frigate Plate Recognizer Version: 1.8.14

which shows the container restarting but apparently for no reason.

After checking docker container logs:

2024-04-12 17:43:36,743 - __main__ - DEBUG - Getting snapshot for event: 1712942357.637452-fh7lyj, Crop: True
2024-04-12 17:43:36,743 - __main__ - DEBUG - event URL: http://frigate.local:5000/api/events/1712942357.637452-fh7lyj/snapshot.jpg
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 198, in _new_conn
sock = connection.create_connection(
File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 60, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/local/lib/python3.9/socket.py", line 954, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
2024-04-12T19:43:36.751830123+02:00
The above exception was the direct cause of the following exception:
2024-04-12T19:43:36.751850393+02:00
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 793, in urlopen
response = self._make_request(
File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 496, in _make_request
conn.request(
File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 400, in request
self.endheaders()
File "/usr/local/lib/python3.9/http/client.py", line 1280, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.9/http/client.py", line 1040, in _send_output
self.send(msg)
File "/usr/local/lib/python3.9/http/client.py", line 980, in send
self.connect()
File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 238, in connect
self.sock = self._new_conn()
File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 205, in _new_conn
raise NameResolutionError(self.host, self, e) from e
urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPConnection object at 0x7f66d7cd7b20>: Failed to resolve 'frigate.local' ([Errno -2] Name or service not known)
2024-04-12T19:43:36.756761564+02:00
The above exception was the direct cause of the following exception:
2024-04-12T19:43:36.756820132+02:00
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 486, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 847, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='frigate.local', port=5000): Max retries exceeded with url: /api/events/1712942357.637452-fh7lyj/snapshot.jpg?crop=True&quality=95 (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f66d7cd7b20>: Failed to resolve 'frigate.local' ([Errno -2] Name or service not known)"))
2024-04-12T19:43:36.758309349+02:00
During handling of the above exception, another exception occurred:
2024-04-12T19:43:36.758360639+02:00
Traceback (most recent call last):
File "/usr/src/app/./index.py", line 583, in <module>
main()
File "/usr/src/app/./index.py", line 579, in main
run_mqtt_client()
File "/usr/src/app/./index.py", line 538, in run_mqtt_client
mqtt_client.loop_forever()
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
rc = self._loop(timeout)
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 1164, in _loop
rc = self.loop_read()
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 1556, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
return self._handle_publish()
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 3327, in _handle_publish
self._handle_on_message(message)
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
on_message(self, self._userdata, message)
File "/usr/src/app/./index.py", line 459, in on_message
snapshot = get_snapshot(frigate_event_id, frigate_url, True)
File "/usr/src/app/./index.py", line 324, in get_snapshot
response = requests.get(snapshot_url, params={ "crop": cropped, "quality": 95 })
File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='frigate.local', port=5000): Max retries exceeded with url: /api/events/1712942357.637452-fh7lyj/snapshot.jpg?crop=True&quality=95 (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f66d7cd7b20>: Failed to resolve 'frigate.local' ([Errno -2] Name or service not known)"))

which shows a different story.

The way the Dockerfile calls python directly is the source of the issue. I don't know how you would prefer to handle this, to me the first solution that comes to mind would be to keep the logger logging out to stdout but not to the file. Then modify the launcher command either directly in the Dockerfile or create a run.sh like:

#!/bin/bash
python index.py >>/config/frigate_plate_recognizer.log 2>&1
dtlr7 commented 3 weeks ago

Hi, I'm having the same issue. Can you elaborate on your solution. Many Thanks!