On Thu, 2011-03-24 at 18:09 -0700, drebbin wrote: > Hi all, > > > I have setup auth and authz as described in the docs, together with > open_id. For testing, I have made a simple secured view and have also > set up the "Forbidden" view as a login form. > As anonymous, logging in by hand and then visiting the secured page > works fine. But when I directly access the secured page, instead of > presenting the login form, an error occurs. From the Apache log:
Try to not use resource_url in the forbidden handler. If you do, use, resource_url(self.request.context, self.request, ...) or resource_url(self.request.root, self.request) > > > > Error - <type 'exceptions.AttributeError'>: 'Forbidden' object has no > attribute '__name__' > URL: http://morrigan.annwn.local/3/secure > File > '/home/my_env/lib/python2.6/site-packages/WebError-0.10.3-py2.6.egg/weberror/errormiddleware.py', > line 162 in __call__ > app_iter = self.application(environ, sr_checker) > File > '/home/my_env/lib/python2.6/site-packages/repoze.tm2-1.0b1-py2.6.egg/repoze/tm/__init__.py', > line 23 in __call__ > result = self.application(environ, save_status_and_headers) > File '/home/my_env/lib/python2.6/site-packages/pyramid/router.py', > line 180 in __call__ > response = view_callable(why, request) > File '/home/my_env/lib/python2.6/site-packages/pyramid/config.py', > line 2824 in _rendered_view > response = wrapped_view(context, request) > File '/home/my_env/lib/python2.6/site-packages/pyramid/config.py', > line 2906 in _class_view > response = getattr(inst, attr)() > File '/home/my_env/OriNet/orinet/views/whoami.py', line 27 in login > do_login_url = resource_url(self.context, self.request, > 'dologin.html') > File '/home/my_env/lib/python2.6/site-packages/pyramid/url.py', line > 290 in resource_url > resource_url = context_url() > File '/home/my_env/lib/python2.6/site-packages/pyramid/traversal.py', > line 692 in __call__ > physical_path = resource_path(resource) > File '/home/my_env/lib/python2.6/site-packages/pyramid/traversal.py', > line 159 in resource_path > return _join_path_tuple(resource_path_tuple(resource, *elements)) > File '/home/my_env/lib/python2.6/site-packages/pyramid/traversal.py', > line 369 in resource_path_tuple > return tuple(_resource_path_list(resource, *elements)) > File '/home/my_env/lib/python2.6/site-packages/pyramid/traversal.py', > line 381 in _resource_path_list > path = [loc.__name__ or '' for loc in lineage(resource)] > AttributeError: 'Forbidden' object has no attribute '__name__' > > > The code that produces it is: > > > class WhoAmI(object): > def __init__(self, context, request): > self.request = request > self.context = context > > > @action(renderer="whoami/login.mak") > # Get also called on a Forbidden exception > @view_config(context=Forbidden, renderer="whoami/login.mak") > def login(self): > #login_url = route_url('whoami', self.request, action="login") > do_login_url = resource_url(self.context, self.request, > 'dologin.html') > this_url = route_url('whoami', self.request, action="login") > root_url = resource_url(self.context, self.request) > referrer = self.request.url > if referrer == do_login_url: > referrer = root_url # never use the login form itself as > came_from > if referrer == this_url: > referrer = root_url # never use the login form itself as > came_from > self.request.session['came_from'] = referrer > openid_url = self.request.registry.settings['openid.url'] > return dict( > do_login_url = do_login_url > , openid_url = openid_url > ) > > > Recently, I had not used "resource_url()" but had hard-coded the URLs. > That worked. So the problem must be within resource_url() and the > context "Forbidden". > Does anybody have a solution for this? > Thanks. > KR, drebbin > > -- > 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 pylons-discuss > [email protected]. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. -- 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.
