Pre-requisite:
1- Admin role user which has authority to change the password
2- user's username of which password will change
3- New password of the user's username
User: test
Admin User: f5osadmin
Python: working on 2.7 and 3
import requests
from requests.auth import HTTPBasicAuth
import json
import urllib3
urllib3.disable_warnings()
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # suppress SSL error
def change_password(b, url, creds):
payload = { }
payload['password'] = creds[0]
#print("Payload: ", payload)
response1 = b.patch(url, data=json.dumps(payload))
#print(response1.content)
#print(response1.status_code)
#print(response1.request.body)
# Return Boolean
if response1 .status_code == int(200):
pass_bool= True
return pass_bool
elif response1 .status_code == int(400) or response1 .status_code == int(401) :
pass_bool= False
return pass_bool
###### TO CHANGE Other non admin user PASSWORD ##################
creds=["MyNewPassword123!"] # user "test" new password
b = requests.session()
b.auth = ('f5osadmin', 'f5OsaDm1n!') # F5 admin role user credentials.
b.verify = False
b.headers.update({'Content-Type':'application/json'})
if change_password(b, 'https://f5.sik.domain.com/mgmt/tm/auth/user/test', creds): # user test
print("password change successful")
else:
print("password change failed")
###### END TO CHANGE PASSWORD ##################
Above is basic python code with few verification in print and which can be enhance with try exception
Hope this will help