OK, so appropriate forms of both request.vars and request.args should work, depending on how the URL is formed. Thanks for explaining the distinction.
IN any case, request.vars.token does work for sure. Thanks again to everyone for their input. On Sep 16, 1:33 pm, Jonathan Lundell <jlund...@pobox.com> wrote: > On Sep 16, 2011, at 10:02 AM, Eric wrote: > > > > > > > > > > > request.args(0) does not seem to work. When I try Massimo's > > suggestion for a token check, I get the traceback below on the error > > ticket. I've tested the database query, and it works fine. Also, the > > service call works fine when I remove the token check. This is what I > > get when I use curl to call > >https://mysite.com/myapp/api/call/run/myservice?token=cxvkYdjuH8azQnB... > > > Traceback (most recent call last): > > File "/home/www-data/web2py/gluon/restricted.py", line 192, in > > restricted > > exec ccode in environment > > File "/home/www-data/web2py/applications/app/controllers/api.py", > > line 60, in <module> > > File "/home/www-data/web2py/gluon/globals.py", line 145, in <lambda> > > self._caller = lambda f: f() > > File "/home/www-data/web2py/applications/app/controllers/api.py", > > line 53, in call > > if row.token == token: > > AttributeError: 'NoneType' object has no attribute 'token' > > > It would appear that the request.vars(0) is getting a None result when > > I try to grab it. What am I doing wrong? > > request.args(0) (not vars) assumes a url like .../run/myservice/cxfkY..., > though it seems to me that'd be args(2). > > But as you've written the URL, you'd get the token as request.vars.token, I > think. > > > > > > > > > > > Thank you, > > > Eric > > > On Sep 15, 11:15 pm, Massimo Di Pierro <massimo.dipie...@gmail.com> > > wrote: > >> Looking at your code again: > > >> @auth.requires_login() > >> def call(token): > >> row = db(db.subscription.token == token).select().first() > >> my_number = row.my_calls > >> if my_number > 0 & my_token == token: > >> db(db.subscription.token == > >> my_token).update(my_calls=db.subscription.my_calls-1) > >> return service() > >> else: > >> raise Exception() > > >> I see two problems: > >> 1) > >> you have both @auth.requires_login() which only works if you enable > >> auth.allow_basic_login = True > >> and you have token authentication. Are you sure you want two > >> authentications one on top of the other? > >> 2) > >> call is a method and cannot take arguments. > > >> If your intention is passing the token as request.args(0) simply do: > > >> def call(): > >> token = request.args(0) # grab the token > >> row = db(db.subscription.token == token).select().first() > >> my_number = row.my_calls > >> if my_number > 0 & my_token == token: > >> db(db.subscription.token == > >> my_token).update(my_calls=db.subscription.my_calls-1) > >> del request.args[0] # make sure you remove the token else you > >> may mess-up some services. > >> return service() > >> else: > >> raise Exception()