ZoneMinder / mlapi

An easy to use/extend object recognition API you can locally install. Python+Flask. Also works with ZMES!
Other
58 stars 34 forks source link

Unable to run mlapi as a service. Something to do with @jwt_required() #39

Closed freffkg closed 3 years ago

freffkg commented 3 years ago

I was running mlapi manually (not a system service) and having a problem with errors reported in zoneminder log. After some research I found someone with a similar problem found that there was some change to flask-jwt-extended version 4.0.0+? There was a recommendation to change @jwt_required to @jwt_required() https://github.com/vimalloc/flask-jwt-extended/issues/175

So I edited mlapi.py and changed class Detect(Resource): @jwt_required

to class Detect(Resource): @jwt_required()

at that point object detection started working great and I could see from the logs output to screen by mlapi that it was processing as expected. Happy days, I thought that I fixed the problem.

So I went ahead and tried to install mlapi as a service and unfortunately the service will not start with the @jwt_required()

So I next changed mlapi.py back to the original, without (). With the original mlapi.py it will start and run as a system service. However, unfortunately this puts me back in the starting condition where I get strange errors in zoneminder log such as shown below. Changing back to @jwt_required() and running manually, not as a system service works. Sorry I am not much of a python programmer so I don't really know what is going on or how to fix this. Any help getting to this work as a system service would be appreciated. The system service runs as www-data, when I run it with the extra () I use sudo and run it as root. So I don't know if maybe that has anything to do with it at all.

2021-04-11 15:21:18 zmesdetect_m10   115518 ERR Error during remote post: 422 Client Error: UNPROCESSABLE ENTITY for url: http://192.168.2.4:5000/api/v1/detect/object?type=object&delete=True&response_format=zm_detect zm_detect.py 158
2021-04-11 15:21:18 zmesdetect_m10   115518 ERR Error with remote mlapi:422 Client Error: UNPROCESSABLE ENTITY for url: http://192.168.2.4:5000/api/v1/detect/object?type=object&delete=True&response_format=zm_detect zm_detect.py 390
2021-04-11 15:21:18 zmesdetect_m10   115518 FAT Unrecoverable error:'NoneType' object is not subscriptable Traceback:Traceback (most recent call last): File "/var/lib/zmeventnotification/bin/zm_detect.py", line 547, in main_handler() File "/var/lib/zmeventnotification/bin/zm_detect.py", line 430, in main_handler 'labels': matched_data['labels'],TypeError: 'NoneType' object is not subscriptable zm_detect.py 552
2021-04-11 15:20:32 zmesdetect_m11   115483 FAT Unrecoverable error:'NoneType' object is not subscriptable Traceback:Traceback (most recent call last): File "/var/lib/zmeventnotification/bin/zm_detect.py", line 547, in main_handler() File "/var/lib/zmeventnotification/bin/zm_detect.py", line 430, in main_handler 'labels': matched_data['labels'],TypeError: 'NoneType' object is not subscriptable zm_detect.py 552
2021-04-11 15:20:32 zmesdetect_m11   115483 ERR Error with remote mlapi:422 Client Error: UNPROCESSABLE ENTITY for url: http://192.168.2.4:5000/api/v1/detect/object?type=object&delete=True&response_format=zm_detect zm_detect.py 390
2021-04-11 15:20:32 zmesdetect_m11   115483 ERR Error during remote post: 422 Client Error: UNPROCESSABLE ENTITY for url: http://192.168.2.4:5000/api/v1/detect/object?type=object&delete=True&response_format=zm_detect zm_detect.py 158
2021-04-11 15:20:20 zmesdetect_m10   115463 ERR Error during remote post: 422 Client Error: UNPROCESSABLE ENTITY for url: http://192.168.2.4:5000/api/v1/detect/object?type=object&delete=True&response_format=zm_detect zm_detect.py 158
2021-04-11 15:20:20 zmesdetect_m10   115463 ERR Error with remote mlapi:422 Client Error: UNPROCESSABLE ENTITY for url: http://192.168.2.4:5000/api/v1/detect/object?type=object&delete=True&response_format=zm_detect zm_detect.py 390
2021-04-11 15:20:20 zmesdetect_m10   115463 FAT Unrecoverable error:'NoneType' object is not subscriptable Traceback:Traceback (most recent call last): File "/var/lib/zmeventnotification/bin/zm_detect.py", line 547, in main_handler() File "/var/lib/zmeventnotification/bin/zm_detect.py", line 430, in main_handler 'labels': matched_data['labels'],TypeError: 'NoneType' object is not subscriptable zm_detect.py 552
2021-04-11 15:19:19 zmesdetect_m10   115430 FAT Unrecoverable error:'NoneType' object is not subscriptable Traceback:Traceback (most recent call last): File "/var/lib/zmeventnotification/bin/zm_detect.py", line 547, in main_handler() File "/var/lib/zmeventnotification/bin/zm_detect.py", line 430, in main_handler 'labels': matched_data['labels'],TypeError: 'NoneType' object is not subscriptable zm_detect.py 552
2021-04-11 15:19:19 zmesdetect_m10   115430 ERR Error with remote mlapi:422 Client Error: UNPROCESSABLE ENTITY for url: http://192.168.2.4:5000/api/v1/detect/object?type=object&delete=True&response_format=zm_detect zm_detect.py 390
2021-04-11 15:19:19 zmesdetect_m10   115430 ERR Error during remote post: 422 Client Error: UNPROCESSABLE ENTITY for url: http://192.168.2.4:5000/api/v1/detect/object?type=object&delete=True&response_format=zm_detect zm_detect.py 158
pliablepixels commented 3 years ago

Stick with what mlapi requires https://github.com/pliablepixels/mlapi/blob/master/requirements.txt

freffkg commented 3 years ago

Thank you for pointing me in the right direction. pip kept installing version 4.0 even though I explicitly asked for version 3.25.0 I was able to get the right package installed with the following and things seems to be working well.

pip install --no-cache-dir --upgrade Flask-JWT-Extended==3.25.0

pliablepixels commented 3 years ago

The right process is to actually use requirements.txt like so: sudo -H pip3 install -r requirements.txt as described in the readme

freffkg commented 3 years ago

yes I followed those instructions and used that command. It somehow gave me the 4.0 version which I had to fix.