import requests import json import sys import hashlib prot = 'http' host = '192.168.42.187' user = '0001' pw = 'starface' if (len(sys.argv) > 1): host = sys.argv[1] if (len(sys.argv) > 2): user = sys.argv[2] if (len(sys.argv) > 3): pw = sys.argv[3] if (len(sys.argv) > 4): prot=sys.argv[4] url = prot + '://' + host + '/rest/login' templateResponse = requests.get(url, headers={'Content-Type':'application/json', 'X-Version':'2'}, verify=False) templateJson = json.loads(templateResponse.content) #print(templateResponse.text) userandnonce=(user+templateJson['nonce']).encode(encoding='utf_8', errors='strict') hpassword=hashlib.sha512(pw.encode(encoding='utf_8', errors='strict')).hexdigest() passwordHashed=hpassword.encode(encoding='utf_8') hsecret = hashlib.sha512(userandnonce+passwordHashed).hexdigest().encode(encoding='utf_8') #print 'secret: ' + hsecret secretCompound=user+':'+hsecret.decode(encoding='utf_8') templateJson['secret'] = secretCompound #print templateJson authTokenResponse = requests.post(url, data=json.dumps(templateJson), headers={'Content-Type':'application/json', 'X-Version':'2'}, verify=False) authtoken = json.loads(authTokenResponse.content)['token'] print('authToken: ' + authtoken) url = 'http://' + host + '/rest/users' userCreateData={"language": "en", "email": "lando@calrissianindustries.galaxy", "password": "starface", "login": "12", "namespace": "", "familyName": "Calrissian", "firstName": "Lando", "missedCallReport": "true", "faxCallerId": "0049721987654321", "faxHeader": "Lando Calrissian", "faxCoverPage": "true", "faxEmailJournal": "true"} userCreate=json.dumps(userCreateData) #templateResponse = requests.get(url, headers={'Content-Type':'application/json', 'X-Version':'2'}) templateResponse = requests.post(url, data=userCreate, headers={'Content-Type':'application/json', 'X-Version':'2', 'authToken':authtoken}) #templateJson = json.loads(templateResponse.content) print(templateResponse.status_code)