step1: I'm grabbing credentials from a text file where data is in JSON format and storing them in a variable.
cred_values = {'username': 'myuser', 'password': 'mypwd'}
Step2:
username = cred_values['username']
password = cred_values['password']
Step3: Preparing my payload, headers. And payload looks like this
login_headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache',
'Origin': 'https://xxxxxx.com.au', 'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'en-US,en;q=0.9',
}
login_data = {
'curl': 'Z2FxxxxxZ2F', (xxxx - name of my company)
'flags': '0',
'forcedownlevel': '0',
'formdir': '5',
'username': username,
'password': password,
'trusted': '4',
'SubmitCreds': ''
}
Step 4: Post request
login_request_url = 'https://xxxx.com.au/Logon'
login_response = requests.post(login_request_url, headers=login_headers, data=login_data)
Note:
I also tried sending payload as
login_data = {'username': '' + username + '','password': '' + password + ''} login_data = {'username': '' + str(username) + '','password': '' + str(password) + ''}
I also tried sending payload as json.dumps to the request
login_response = requests.post(login_request_url, headers=login_headers, data=json.dumps(login_data))
I'm not getting any errors if I post the above request its not logging in.
Ex:
If I directly add my username, pwd in login_data
The Url looks like this, which means successfully logged in - 'https://xxxx.com.au/content.asp?token = xxxxx'
If I send username and pwd by grabbing from credential file
The Url looks like this which means NOT successfully logged in - 'https://xxxx.com.au/'
login_headers
is undefined. Please post your real code. – John Gordonjson=
instead of data= – pale bone