ep1cman / unifi-protect-backup

Python tool to backup unifi event clips in realtime
MIT License
633 stars 31 forks source link

Unexpected exception occurred during missing event check: Status: 401 - Reason: {'code': 401, 'message': 'Unauthorized'} #135

Closed Swallowtail23 closed 6 months ago

Swallowtail23 commented 6 months ago

Description

Several times a day, UPB pops the following error.

2024-03-22T18:19:03.179907871+10:00 stderr F 2024-03-22 08:19:03 [   DEBUG   ] unifi_protect_backup.downloader            : [65fd3ee503714e03e425db52]    Downloaded video size: 14.8MiBs
2024-03-22T18:19:03.242998781+10:00 stderr F 2024-03-22 08:19:03 [   DEBUG   ] unifi_protect_backup.downloader            : [65fd3ee503714e03e425db52]    Downloaded video length: 12.375s(+0.341s)
2024-03-22T18:19:03.243040670+10:00 stderr F 2024-03-22 08:19:03 [   DEBUG   ] unifi_protect_backup.downloader            : [65fd3ee503714e03e425db52]  Added to upload queue
2024-03-22T18:19:03.246871137+10:00 stderr F 2024-03-22 08:19:03 [   INFO    ] unifi_protect_backup.uploader              : [65fd3ee503714e03e425db52]  Uploading event: 65fd3ee503714e03e425db52
2024-03-22T18:19:03.246914797+10:00 stderr F 2024-03-22 08:19:03 [   DEBUG   ] unifi_protect_backup.uploader              : [65fd3ee503714e03e425db52]   Remaining Upload Queue: 0 (0.0B)
2024-03-22T18:19:03.247032115+10:00 stderr F 2024-03-22 08:19:03 [   DEBUG   ] unifi_protect_backup.uploader              : [65fd3ee503714e03e425db52]   Destination: AWS:simonandkate.net/Unifi-Protect-Backup/Patio Camera/2024-03-22/2024-03-22T18-18-43 smartDetectZone (person).mp4
2024-03-22T18:19:08.115618805+10:00 stderr F 2024-03-22 08:19:08 [   DEBUG   ] unifi_protect_backup.uploader              : [65fd3ee503714e03e425db52]  Uploaded
2024-03-22T18:20:57.852342230+10:00 stderr F 2024-03-22 08:20:57 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T18:26:02.739063358+10:00 stderr F 2024-03-22 08:26:02 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T18:31:07.597961361+10:00 stderr F 2024-03-22 08:31:07 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T18:36:12.582367446+10:00 stderr F 2024-03-22 08:36:12 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T18:41:17.530627074+10:00 stderr F 2024-03-22 08:41:17 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T18:46:22.317342619+10:00 stderr F 2024-03-22 08:46:22 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T18:51:27.350673534+10:00 stderr F 2024-03-22 08:51:27 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T18:56:32.096330513+10:00 stderr F 2024-03-22 08:56:32 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T19:01:36.851605715+10:00 stderr F 2024-03-22 09:01:36 [   DEBUG   ] unifi_protect_backup.missing_event_checker :  Running check for missing events...
2024-03-22T19:01:36.918963391+10:00 stderr F 2024-03-22 09:01:36 [   ERROR   ] unifi_protect_backup.missing_event_checker :  Unexpected exception occurred during missing event check:
2024-03-22T19:01:36.918963391+10:00 stderr F Traceback (most recent call last):
2024-03-22T19:01:36.918963391+10:00 stderr F   File "/usr/lib/python3.11/site-packages/unifi_protect_backup/missing_event_checker.py", line 151, in start
2024-03-22T19:01:36.918963391+10:00 stderr F     async for event in self._get_missing_events():
2024-03-22T19:01:36.918963391+10:00 stderr F   File "/usr/lib/python3.11/site-packages/unifi_protect_backup/missing_event_checker.py", line 65, in _get_missing_events
2024-03-22T19:01:36.918963391+10:00 stderr F     events_chunk = await self._protect.get_events(
2024-03-22T19:01:36.918963391+10:00 stderr F                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-03-22T19:01:36.918963391+10:00 stderr F   File "/usr/lib/python3.11/site-packages/pyunifiprotect/api.py", line 779, in get_events
2024-03-22T19:01:36.918963391+10:00 stderr F     response = await self.get_events_raw(
2024-03-22T19:01:36.918963391+10:00 stderr F                ^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-03-22T19:01:36.918963391+10:00 stderr F   File "/usr/lib/python3.11/site-packages/pyunifiprotect/api.py", line 749, in get_events_raw
2024-03-22T19:01:36.918963391+10:00 stderr F     return await self.api_request_list("events", params=params)
2024-03-22T19:01:36.918963391+10:00 stderr F            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-03-22T19:01:36.918963391+10:00 stderr F   File "/usr/lib/python3.11/site-packages/pyunifiprotect/api.py", line 384, in api_request_list
2024-03-22T19:01:36.918963391+10:00 stderr F     data = await self.api_request(
2024-03-22T19:01:36.918963391+10:00 stderr F            ^^^^^^^^^^^^^^^^^^^^^^^
2024-03-22T19:01:36.918963391+10:00 stderr F   File "/usr/lib/python3.11/site-packages/pyunifiprotect/api.py", line 342, in api_request
2024-03-22T19:01:36.918963391+10:00 stderr F     data = await self.api_request_raw(
2024-03-22T19:01:36.918963391+10:00 stderr F            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-03-22T19:01:36.918963391+10:00 stderr F   File "/usr/lib/python3.11/site-packages/pyunifiprotect/api.py", line 317, in api_request_raw
2024-03-22T19:01:36.918963391+10:00 stderr F     raise NotAuthorized(msg % (url, response.status, reason))
2024-03-22T19:01:36.918963391+10:00 stderr F pyunifiprotect.exceptions.NotAuthorized: Request failed: /proxy/protect/api/events - Status: 401 - Reason: {'code': 401, 'message': 'Unauthorized'}

What I Did

Nothing out of the ordinary. UPB is working fine, and events are getting backed up (not sure whether the errors are resulting in fails, or retries.

Config: podman run \ -e UFP_USERNAME='unifiprotectbackup' \ -e UFP_PASSWORD='xxxxxxxxxxxx' \ -e UFP_ADDRESS='192.168.1.18' \ -e UFP_SSL_VERIFY='false' \ -e RCLONE_RETENTION='120d' \ -e DETECTION_TYPES='person','vehicle','ring' \ -e RCLONE_ARGS='--checksum' \ -e RCLONE_DESTINATION='AWS:simonandkate.net/Unifi-Protect-Backup' \ -e VERBOSITY='v' \ -e APPRISE_NOTIFIERS='pover://xxxxxx@xxxxxxxx' \ -e COLOR_LOGGING \ -e DOWNLOAD_BUFFER_SIZE='1536MiB' \ -v '/opt/upb-docker/data/':'/data' \ -v '/opt/upb-docker/database/':'/config/database' \ -v '/opt/upb-docker/conf/':'/config/rclone' \ --tz=Australia/Brisbane \ ghcr.io/ep1cman/unifi-protect-backup:0.10.3

ep1cman commented 6 months ago

I am about to push a new release that fixes issues introduced with the latest Unifi Protect release. Can you try this and let me know if this keeps happening?

Swallowtail23 commented 6 months ago

I've updated to 0.10.7 this morning, will see how it goes. I reduced retention period AND changed rclone destination so at the moment it's ploughing through hundreds of "can't delete that event as I can't find it"... once that has all cleared up to the new retention period I'll settle and watch how it goes. Note that it has been doing this error for a couple of versions prior to 0.10.3, I've just not had time to post it.

Swallowtail23 commented 6 months ago

OK, so a few hours in and so far so good... I'll close this after a couple of days if it remains clear.

Swallowtail23 commented 6 months ago

I think your 0.10.7 has resolved whatever this was - thanks. Closing.