ZoneMinder / zmeventnotification

Machine Learning powered Secure Websocket & MQTT based ZoneMinder event notification server
412 stars 128 forks source link

Basic Authentication fails for zm_detect.py #392

Closed CV8R closed 3 years ago

CV8R commented 3 years ago

Event Server version 6.1.22

Hooks version (if you are using Object Detection) app:6.1.22, pyzm:0.3.47

Are you using MLAPI? (Y/N) N

The version of ZoneMinder you are using: v1.34.23

What is the nature of your issue

Question

Details

When enabling Basic Authentication in Apache and Hooks in the ES I get authentication errors in the debug log from zm_detect.py regardless of the basic auth credentials I have entered into the .ini files.

I've run out of steam trying to understand where I may be going wrong.

sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py --config /etc/zm/objectconfig.ini  --eventid 996 --monitorid 4 --debug

Results in:

Unrecoverable error:401 Client Error: Unauthorized for url:

I have set the basic auth credentials in objectconfig.ini

# If you need basic auth to access ZM
basic_user=correct_username
basic_password=correct_pass

If I disable basic auth in the Apache config zm_detect.py authenticates and the Machine Learning hooks work and notifications come through for detections.

If I enable basic auth in the Apache config and disable the hooks in the ES works notifications come through to ZMNinja as expected.

Debug Logs (if applicable)


sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py --config /etc/zm/objectconfig.ini  --eventid 996 --monitorid 4 --debug

04/16/21 22:53:14 zmesdetect_m4[134254] INF ZMLog.py:225 [Setting up signal handler for logs]

04/16/21 22:53:14 zmesdetect_m4[134254] INF ZMLog.py:234 [Switching global logger to ZMLog]

04/16/21 22:53:14 zmesdetect_m4[134254] INF zm_detect.py:271 [---------| app:6.1.22, pyzm:0.3.47, ES:6.1.22 , OpenCV:4.5.1|------------]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG1 utils.py:410 [secret filename: /etc/zm/secrets.ini]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG2 utils.py:383 [Secret token found in config: !ZM_PORTAL]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG2 utils.py:383 [Secret token found in config: !ZM_USER]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG2 utils.py:383 [Secret token found in config: !ZM_PASSWORD]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG2 utils.py:383 [Secret token found in config: !ZM_API_PORTAL]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG2 utils.py:383 [Secret token found in config: !ML_USER]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG2 utils.py:383 [Secret token found in config: !ML_PASSWORD]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG2 utils.py:383 [Secret token found in config: !PLATEREC_ALPR_KEY]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG1 utils.py:447 [strict SSL cert checking is on...]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG4 utils.py:455 [Now checking for monitor overrides]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG4 utils.py:473 [[monitor-4] overrides key:match_past_detections with value:no]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG4 utils.py:473 [[monitor-4] overrides key:wait with value:5]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG2 utils.py:491 [model_sequence is not a polygon, adding it as unknown string key]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG4 utils.py:473 [[monitor-4] overrides key:object_detection_pattern with value:(person)]

04/16/21 22:53:14 zmesdetect_m4[134254] DBG4 utils.py:523 [Finally, doing parameter substitution]

04/16/21 22:53:14 zmesdetect_m4[134254] INF zm_detect.py:296 [Importing local classes for Object/Face]

04/16/21 22:53:15 zmesdetect_m4[134254] INF zm_detect.py:319 [Connecting with ZM APIs]

04/16/21 22:53:15 zmesdetect_m4[134254] DBG1 api.py:176 [using username/password for login]

04/16/21 22:53:15 zmesdetect_m4[134254] ERR api.py:226 [Got API login error: 401 Client Error: Unauthorized for url: https://www.aplace.com/zm/api/host/login.json]

04/16/21 22:53:15 zmesdetect_m4[134254] FAT zm_detect.py:552 [Unrecoverable error:401 Client Error: Unauthorized for url: https://www.aplace.com/zm/api/host/login.json Traceback:Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 547, in <module>
    main_handler()
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 320, in main_handler
    zmapi = zmapi.ZMApi(options=api_options)
  File "/usr/local/lib/python3.8/dist-packages/pyzm/api.py", line 75, in __init__
    self._login()
  File "/usr/local/lib/python3.8/dist-packages/pyzm/api.py", line 228, in _login
    raise err
  File "/usr/local/lib/python3.8/dist-packages/pyzm/api.py", line 198, in _login
    r.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://www.aplace.com/zm/api/host/login.json
]

Thanks!