List Info

Thread: Newbie - Problem with Sessions




Newbie - Problem with Sessions
user name
2006-08-26 17:33:00
cbackas wrote:
> Hello all,
>
> I'm evaluating various web technologies for use in my
company, and
> Python is a front-runner language due to the ability it
gives us to
> re-use an extensive Objective-C (Cocoa) codebase.
>
> Anyway, I've been looking into CherryPy on a friend's
enthusiastic
> recommendation, but I can't get a simple test of
sessions to work. When
> I check what headers I'm getting back the browsers all
agree (OmniWeb,
> Safari, FireFox, and even Curl) are agreeing that
they're getting a
> Session ID Cookie. However, the CherryPy server seems
to issue a new
> one for every request instead of maintaining session.
I'm convinced I'm
> overlooking something basic, but I can't see it =)
>
> Below is my script; I'm using a Cheetah template
that's working fine,
> and you can gloss over the strange Apple-ish stuff ;)
The line "print
> "index: " + str(cherrypy.session)" is
always printing a different value
> to console no matter what I do. I'll paste my .conf
file after the
> script.
>
> Thanks for any insight!
>
> Chris Backas
>
>
> #!/usr/local/bin/python
> #  IPWeb.py
> #  IPWeb
> #
> from cherrypy import expose, session, config, server,
NotFound,
> response
> import cherrypy
> from Cheetah.Template import Template
> import sys
> from Foundation import *
> from AppKit import NSBitmapImageRep
> import IPWebFramework
> import IPPostgreSQL
>
>
> def get_page(name):
> 	'''Get a page template'''
> 	return Template(file = '%s.tmpl' % name)
>
> # Connect to PostgreSQL database server
> pgConn = IPWebFramework.WebHelper.connectToPostgres()
>
>
> class IPWebTest:
> 	def index(self,requestID = None, cabinet = None,
carrier = None):
> 		# CherryPy will call this method for the root URI
("/") and send
> 		# its return value to the client.
>
> 		page = get_page("index")
> 		# Initial page
> 		if (requestID is None) or (cabinet is None) or
(carrier is None):
> 			return str(page)
>
> 		cherrypy.session.acquire_lock()
> 		cherrypy.session["requestID"] = requestID
> 		cherrypy.session["cabinet"] = cabinet
> 		cherrypy.session["carrier"] = carrier
> 		print "index: " + str(cherrypy.session)
> 		page.requestID = requestID
> 		page.cabinet = cabinet
> 		page.carrier = carrier
>
> 		return str(page)
> 	index.exposed = 1
>
>
> if __name__ == '__main__':
> 	# Use the configuration file
> 	cherrypy.config.update(file = 'IPWebApp.conf')
> 	cherrypy.config.update({'session_filter.on': True})
> 	# Start the CherryPy server.
> 	cherrypy.tree.mount(IPWebTest())
> 	cherrypy.server.start()
>
>
>
> IPWebAll.conf:
>
> [global]
> server.socketPort = 8080
> server.threadPool = 10
> server.environment = "production"
> server.session_filter.on = 1
> # server.showTracebacks = True
> # server.logToScreen = False

Well, I'm stumped. I ran a test very similar to yours and
got the same
id every time. Perhaps you have cookies disabled?


import cherrypy

class IPWebTest:
    def index(self, requestID = None, cabinet = None,
carrier = None):
        if (requestID is None) or (cabinet is None) or
(carrier is
None):
            return "missing"

        cherrypy.session.acquire_lock()
        cherrypy.session["requestID"] =
requestID
        cherrypy.session["cabinet"] = cabinet
        cherrypy.session["carrier"] = carrier
        print "index: " + str(cherrypy.session)
        return "OK"
    index.exposed = True


if __name__ == '__main__':
    cherrypy.config.update({'server.socketPort': 8080,
                            'server.threadPool': 10,
                            'server.environment':
"production",
                            'session_filter.on': True,
                            'server.log_to_screen': False,
                            })
    cherrypy.tree.mount(IPWebTest())
    cherrypy.server.start()




index: {'carrier': 'c', '_id':
'b2e0af86bc9b7f8fa0e9ab6b0970c7fad097b680', 'requestID':
'a',
'cabinet': 'b'}
index: {'carrier': 'd', '_id':
'b2e0af86bc9b7f8fa0e9ab6b0970c7fad097b680', 'requestID':
'a',
'cabinet': 'b'}
index: {'carrier': 'e', '_id':
'b2e0af86bc9b7f8fa0e9ab6b0970c7fad097b680', 'requestID':
'a',
'cabinet': 'b'}
index: {'carrier': 'f', '_id':
'b2e0af86bc9b7f8fa0e9ab6b0970c7fad097b680', 'requestID':
'a',
'cabinet': 'b'}


Robert Brewer
System Architect
Amor Ministries
fumanchuamor.org


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Newbie - Problem with Sessions
user name
2006-08-28 15:53:09
I tried your example with the same trouble; and then I
re-tested my
earlier assertions. It appears that it DOES work in Firefox
after all
(I had tried this earlier, I don't know if something else
was wrong at
the time that made me think otherwise or not...)

But I don't understand why there's a difference between
Firefox and
OmniWeb and Safari in this regard. I'm 100% certain that
Cookies are
not disabled in either, I use plenty of sites that would
have trouble
if they were. OmniWeb will show me the cookie it receives
from
CherryPy, with the _id matching exactly what the AppServer
shows me as
the last generated Cookie, and it's marked as
"Saved" (as opposed to
either "Rejected" or "Temporary")

It looks like, for whatever reason, CherryPy is not
accepting/recognizing/??? the cookie on the return request
from
browsers other than Firefox though. Is there someplace I can
look/something I can enable in the AppServer to debug this?

Thanks!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Newbie - Problem with Sessions
user name
2006-08-28 17:41:40
Ok, I figured this out finally. For some reason, WebKit (on
which
Safari and OmniWeb are based) seems to throw out cookies
coming from
localhost despite giving every indication it's not -
replacing
'localhost' with my own local IP fixed it, and indeed it
works from
remote machines.

Sorry for wasting everyone's time =)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )