0

I am writing a python script to submit a post request with data. I got the below programme which works fine for login. and i get value "cloud" for a.text. but i am not able to submit next post request to the server because the in php application i have isset($_SESSION['user_name']. if user_name is not set then it will redirect to homepage. the below code redirects to home page. I want to set the a.text to $_SESSION[user_name]. how to do it

import requests
loginurl = 'http:localhost/login.php'
loginparams = {'username': 'admin', 'password' : '1234'}
targeturl = 'http:localhost/add.php'
params={'firstname':'cloud', 'lastname':'kicker'}

def main():
    login = requests.Session()
    a = login.post(loginurl, loginparams)
    print a.text # i get username for this line
    login.post(targeturl, params, cookies={'user_name': a.text})
    return 0
if __name__ == '__main__':
    main()

1 Answer 1

0

i updated the below line and it worked for me

login.post(targeturl, params, cookies={'user_name': a.text})

login.post(targeturl, targetdata, cookies=dict(login.cookies))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.