{solved} Api error 401 since last update

Forum for questions and support relating to 1.33.x development only.
Locked
fennec
Posts: 59
Joined: Thu Mar 20, 2014 1:17 am

{solved} Api error 401 since last update

Post by fennec »

Hi

After update to 1.33.14

i have always error 401

i use script python
import requests

log="http://10.0.0.1/index.php"
login_post = {'view': 'console', 'action': 'login', 'username': username, 'password': password}
req=requests.post(log,data=login_post)
cook=req.cookies
req=requests.get('http://10.0.0.1/zm/api/host/getVersion. ... okies=cook)
print req
do you know why

thanks a lot
Last edited by fennec on Thu Sep 05, 2019 2:04 pm, edited 1 time in total.
fennec
Posts: 59
Joined: Thu Mar 20, 2014 1:17 am

Re: Api error 401 since last update

Post 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
}
}
}
}
fennec
Posts: 59
Joined: Thu Mar 20, 2014 1:17 am

Re: Api error 401 since last update

Post 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'})
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: {solved} Api error 401 since last update

Post by asker »

If you are using APIs, you should switch to the newer token system.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Locked