This python script may helps you. In my case the arcgis server rest end point is through webadaptor and I have the admin option enabled. If you try to access the rest through port 6443 then you have to configure the certificate on ArcGIS Server because a SSL certificate error will arise.
import requests
import json
print("Start -----")
UserName = '<user name>'
PassWord = '<password>'
### GET A TOKEN
print("Getting token")
token_URL = "https://<domain name>/portal/sharing/generateToken"
token_params = {"username":UserName,"password": PassWord,"referer": "https://<domain name>","f":"json","expiration":60}
r = requests.post(token_URL,token_params)
token_obj= r.json()
token = token_obj["token"]
### SET THE PARAMETERS
print("Creating parameters")
newParams = {'f':'json'}
url='https://<domain name>/server/admin/system/licenses?&token={}'.format(token)
### SEND THE REQUEST
print("Sending request")
r = requests.post(url,newParams)
print(r.json())
print("Script complete")