1

In order to automate user registration in my website, I am using

>>> r = requests.post('http://www.dakshnetworks.com:8888/accounts/signup/', data=payload)

That is working well. but once the user is registered, i am directing him to another page where he has to set his workplace. So i tried to use

 o= requests.post('http://www.dakshnetworks.com:8888/set/', data=payload2)

but that is not able to set the workplace of the user returning error 500

[01/Jun/2015 17:11:07] "POST /accounts/signup/ HTTP/1.1" 302 0
[01/Jun/2015 17:11:07] "GET / HTTP/1.1" 302 0
[01/Jun/2015 17:11:07] "GET /set/ HTTP/1.1" 200 26351
[01/Jun/2015 17:14:40] "POST /set HTTP/1.1" 500 75469
[01/Jun/2015 17:16:16] "POST /set/ HTTP/1.1" 500 126509

So how do i maintain the connection so that the server may know that the requests are coming from the same user.

1 Answer 1

2

Use a Session() object to maintain cookies, so that the server knows it is still the same user:

session = requests.Session()
r = session.post('http://www.dakshnetworks.com:8888/accounts/signup/', data=payload)
o = session.post('http://www.dakshnetworks.com:8888/set/', data=payload2)
Sign up to request clarification or add additional context in comments.

7 Comments

now i realize that the second request should be an ajax request. how should i do that
@Rohit: AJAX is just another request. There isn't much of a difference to the server there.
even though I am using session, it is redirecting me to login page when using any method where login is required >>> session = requests.session() >>> e= session.get('dakshnetworks.com:8888/accounts/login', auth=('48948' , 'password')) >>> i = session.get('dakshnetworks.com:8888/user/set_interests')
That's using Basic Auth, are you sure the site doesn't use a login form?
If Basic Auth works, use that username and password for every request or use session.auth = ('48948', 'password') to make the session send it every time.
|

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.