Hi all
I have created a middleware t track campaigns that do one simple thing
- it get parameter from request and set cookie, code looks like
class CampaignTrackingMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
source_id = request.params.get('source_id')
if not is_blank(source_id) and
request.cookies.get('source_id') != source_id:
# print "setting source_id cookie to %s " %
request.params.get('source_id')
response.set_cookie('source_id', source_id,
expires=3600000)
session.save()
return self.app(environ, start_response)
After I'm adding it to the chain in middleware.py
I'm getting the error
..................................................................
File "/opt/workspace/uaprom/uaprom/lib/custom_middleware.py", line
27, in __call__
if not is_blank(request.params.get('source_id')):
File "/sw/lib/python2.5/site-packages/Paste-1.4.2-py2.5.egg/paste/
registry.py", line 125, in __getattr__
return getattr(self._current_obj(), attr)
File "/sw/lib/python2.5/site-packages/Paste-1.4.2-py2.5.egg/paste/
registry.py", line 182, in _current_obj
'thread' % self.____name__)
TypeError: No object (name: Request) has been registered for this
thread
As far as I understand request is not registered at that point, I
tried to move my middleware to the top/bottom of the chain and the
error was still the same. After all I moved the logic to the
__before__ method of BaseController
Is there any way to do such things in the middleware or BaseController
is the right place for that?
Thanks in advance for any help
m
Disclaimer: I came from J2EE world (I hope I never come back to that
enterprise nightmare) and think that Middleware is ServletFilter
analog, I might be wrong.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---