Page 1 of 1
{solved} Api error 401 since last update
Posted: Thu Sep 05, 2019 6:57 am
by fennec
Hi
After update to 1.33.14
i have always error 401
i use script python
do you know why
thanks a lot
Re: Api error 401 since last update
Posted: Thu Sep 05, 2019 10:54 am
by fennec
I try to use api with 1.33.9
i login in web interface and in other windows i open
http://10.0.0.1/zm/api/monitors/1.json
All is ok
on another zoneminder with 1.33.14
i login in web interface and when i open
http://10.0.0.1/zm/api/monitors/1.json
i have error
{
"success": false,
"data": {
"name": "Not Authenticated",
"message": "Not Authenticated",
"url": "\/zm\/api\/monitors\/1.json",
"exception": {
"class": "UnauthorizedException",
"code": 401,
"message": "Not Authenticated",
"trace": [
"#0 \/usr\/share\/zoneminder\/www\/api\/app\/Controller\/MonitorsController.php(23): AppController->beforeFilter()",
"#1 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Event\/CakeEventManager.php(243): MonitorsController->beforeFilter(Object(CakeEvent))",
"#2 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Controller\/Controller.php(677): CakeEventManager->dispatch(Object(CakeEvent))",
"#3 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(189): Controller->startupProcess()",
"#4 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(167): Dispatcher->_invoke(Object(MonitorsController), Object(CakeRequest))",
"#5 \/usr\/share\/zoneminder\/www\/api\/app\/webroot\/index.php(107): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
"#6 {main}"
]
},
"queryLog": {
"default": {
"log": [],
"count": 0,
"time": null
}
}
}
}
Re: Api error 401 since last update
Posted: Thu Sep 05, 2019 2:04 pm
by fennec
Ok Api.2
For information in python
#!/usr/bin/python2
import sys
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
ip="10.0.0.1"
username="user"
password="pass"
session = requests.Session()
session.verify = False
session.post(url='https://'+ip+'/zm/api/host/login.json',data={'user':username,'pass':password, 'stateful':'1'})
session.post(url='https://'+ip+'/zm/api/monitors/1.json',data={'Monitor[Function]' : 'Record'})
Re: {solved} Api error 401 since last update
Posted: Thu Sep 05, 2019 3:55 pm
by asker
If you are using APIs, you should switch to the newer token system.