Logout not working with Python requests module

749 views
Skip to first unread message

Pete

unread,
Jan 12, 2013, 10:23:00 AM1/12/13
to cork-d...@googlegroups.com
Hi There,

I am after some advice please. I have cork working correctly, I can login as a user correctly using HTTP POST and can also get my current username etc when logged in but am having trouble getting requests to logout correctly.

If I point a rest client at my bottle-cork server then the login/logout works fine, if I used the Python requests module the logout appears to work correctly but no cookies are cleared and if I access my get_user_info url I still get the correct username returned etc.

This is my logout method

@bottle.route('/logout')
def logout():
    logout_result = aaa.logout()

my requests code is as follows:

 def __init__(self):
        self.session = requests.session()
        self.session.headers = {'Content-Type':'application/json'}

def logout(self):
            """
            Method to handle logging out of the server
            """
        r = self.session.get(self.LOGOUT_URL)

I have read the documentation and for the life of me cannot identify why this would logout correctly in the rest client but fail using Python requests? Has anyone successful used requests with this who may be able to identify what the problem is?

Many thanks

Federico Ceratto

unread,
Jan 14, 2013, 12:38:03 PM1/14/13
to cork-d...@googlegroups.com
On Sat, Jan 12, 2013 at 3:23 PM, Pete <peter...@gmail.com> wrote:

> I have read the documentation and for the life of me cannot identify why
> this would logout correctly in the rest client but fail using Python
> requests? Has anyone successful used requests with this who may be able to
> identify what the problem is?

Sounds like Bottle is asking Requests to drop the cookie and the
Requests is refusing to do so...
Do you have a code snipped to reproduce the problem?

--
Federico

Peter Baugh

unread,
Jan 14, 2013, 3:54:45 PM1/14/13
to cork-d...@googlegroups.com
I have uploaded two files to pastebin one file is a handler that runs bottle-cork and handles the requests, this can be found here:

http://pastebin.com/8qJpJPPA

I have uploaded another file for testing login/logout with the requests module

http://pastebin.com/fFshAD8g

Looking at the log from the handler which shows the login, get_user_info, logout and the final get_user_info request you can see the logout fail

localhost - - [14/Jan/2013 20:32:57] "POST /login HTTP/1.1" 200 9
localhost - - [14/Jan/2013 20:32:57] "GET /get_user_info HTTP/1.1" 200 52
localhost - - [14/Jan/2013 20:32:57] "GET /logout HTTP/1.1" 303 0
localhost - - [14/Jan/2013 20:32:57] "GET /failure HTTP/1.1" 200 13
localhost - - [14/Jan/2013 20:32:57] "GET /get_user_info HTTP/1.1" 200 52

I noticed that I also always get redirected to '/failue' when logging out, even when using a restclient, although with the restclient the logout works as expected and the cookie is cleared.

Maybe I have overlooked something, either way I would like to get to the bottom of what I am doing wrong or what the problem is with requests?

Many thanks




--
You received this message because you are subscribed to the Google Groups "cork-discuss" group.
To post to this group, send an email to cork-d...@googlegroups.com.
To unsubscribe from this group, send email to cork-discuss...@googlegroups.com.

Pete

unread,
Jan 15, 2013, 9:08:10 AM1/15/13
to cork-d...@googlegroups.com
I just tried this with httplib2 and had the same problem, the cookie does not get cleared when logging out.
To unsubscribe from this group, send email to cork-discuss+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages