{solved} Api error 401 since last update

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

{solved} Api error 401 since last update

Post by fennec » Thu Sep 05, 2019 6:57 am

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: 39
Joined: Thu Mar 20, 2014 1:17 am

Re: Api error 401 since last update

Post by fennec » Thu Sep 05, 2019 10:54 am

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: 39
Joined: Thu Mar 20, 2014 1:17 am

Re: Api error 401 since last update

Post by fennec » Thu Sep 05, 2019 2:04 pm

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: 1082
Joined: Sun Mar 01, 2015 12:12 pm

Re: {solved} Api error 401 since last update

Post by asker » Thu Sep 05, 2019 3:55 pm

If you are using APIs, you should switch to the newer token system.
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest