first time api python code - need newbie help

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
david1234
Posts: 96
Joined: Wed Jun 26, 2019 12:24 pm

first time api python code - need newbie help

Post by david1234 »

Hello
I want to connect to my server using Python API
I have download "pyzm package" ,
and run an simple code to get the version just to see if it's working
this is what I have done:

Code: Select all

import pyzm.api as zmapi

api_options = {
    'apiurl': 'http://10.0.0.105/zm/api',
    'portalurl': 'http:/10.0.0.105/zm',
    'user': 'David',
    'password': 'Davidpass',
    'logger': None # use none if you don't want to log to ZM
}

zmapi = zmapi.ZMApi(options=api_options)

print (zmapi.version())
and I get the wanted answer :

Code: Select all

{'status': 'ok', 'api_version': '2.0', 'zm_version': '1.34.22'}
so all setting are OK and everything is working

I have quesrtions:
1. how do is disable the log
because I get many uneanted rows of the api

Code: Select all

Dec 01 2020 13:06:02.550851 [INF] Using simple log output (default)
Dec 01 2020 13:06:02.551851 [DBG 1] using username/password for login
Dec 01 2020 13:06:03.284893 [DBG 1] Using new token API
Dec 01 2020 13:06:03.284893 [DBG 1] Refresh token expires on:2020-12-02 13:06:03.284893 [86400s]
.
.
.
2. how can I get te server state?
in my server I have 3 states (record , default , stop )
but when I print using this command :

Code: Select all

tates = zmapi.states()
for state in states.list():
    print('State:{}[{}], active={}, details={}'.format(state.name(), state.id(), state.active(), state.definition()))
this is what I get :

Code: Select all

State:default[1], active=False, details=None
State:Record[4], active=True, details=2:None:0,3:Record:1,4:None:0,6:None:0,7:Record:1
as I understand every camera have a number and only cameras 3 and 7 are in "Record" mode - which is correct.

so why does it say active = true ? right now the server is in "Stop" state (also after I change it to "Record" it still return the same answer)

- how do I see the server state?
I want to see the state has change after I change it using (this commands are working , I can see the server is changing to Record \ Stop )

Code: Select all


print('going to stop the server')
server = zmapi.stop()

print('going to start the server')
server = zmapi.set_state("Record")


Thanks ,
Post Reply