When the user is not logged in, auth.user is None, so you get an error when 
trying to access auth.user.id. Instead, you can use auth.user_id, which 
will simply return None when the user isn't logged in rather than an error. 
See the callout at the end of this section in the 
book: http://web2py.com/books/default/chapter/29/9#Authentication.

Anthony

On Saturday, March 17, 2012 12:54:54 PM UTC-4, backseat wrote:
>
> I have a function whose definition starts as follows:
>
> @auth.requires_login()
> def rbb_time(category_id, from_date, to_date, user_id=auth.user.id):
>
> It works fine. I'll leave the development of this application for a few
> days, come back, run it, and get:
>
> Traceback (most recent call last):
>   File "/home/kae/hg/kae/web2py.1.99.4.pytrack2/gluon/restricted.py", line
>   204, in restricted exec ccode in environment
> File "[...]/controllers/default.py", line 100, in <module> 
>   def rbb_time(category_id, from_date, to_date, user_id=auth.user.id): 
> AttributeError: 'NoneType' object has no attribute 'id'
>
> The only way to fix it (and this isn't 100% reliable) is to comment out
> all of the "@auth.requires_login()" lines, hard-code the above function
> definition to end "user_id=11" (the UID I was logged in as), and then
> call /default/user/logout.
>
> Can anyone offer any suggestions as to what is going on here?
>
> Thanks,
> Keith
>
>

Reply via email to