Forum Discussion
lowone
Nimbostratus
Nov 21, 2019REST API example change password
I need to change the password for admin and root accounts on our big-ip servers. I found this api end point but need more info on the parameters or a working example. https://clouddocs.f5...
Shahid_Khan
Nimbostratus
Apr 29, 2020Pre-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
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
