-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
39 lines (29 loc) · 1.19 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
import sys
# Importing models and REST client class from Community Edition version
from tb_rest_client.rest_client_ce import *
# Importing the API exception
from tb_rest_client.rest import ApiException
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
# ThingsBoard REST API URL
url = "http://localhost:9090"
# Default Tenant Administrator credentials
username = "[email protected]"
password = "sysadmin"
def main():
# Creating the REST client object with context manager to get auto token refresh
with RestClientCE(base_url=url) as rest_client:
try:
# Auth with credentials
rest_client.login(username=username, password=password)
# using sys argument 1 to get the new password
new_password = sys.argv[1]
change = ChangePasswordRequest(password, new_password)
# Call change_password_using_post method
rest_client.change_password(body=change)
except ApiException as e:
logging.exception(e)
if __name__ == '__main__':
main()