Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8895325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:44:53+00:00 2026-06-14T23:44:53+00:00

I have written a decorator to authenticate calls. It works fine with only one

  • 0

I have written a decorator to authenticate calls. It works fine with only one argument, but with more it doesn’t, triggering off a inner() takes exactly 1 argument (2 given). I have a bit of a callback spaghetti since I’m using Tornado, but I’m not sure what’s the best way to do this.

#this works
class FirstHandler(BaseHandler):

    @asynchronous
    @oauth_machine.auth
    def post(self):
        print self.user
        self.finish()

#this now also does
class SecondHandler(BaseHandler):

    @asynchronous
    @oauth_machine.auth
    def get(self, args):
        self.write("ok")
        self.finish()

The decorator function(s)

def auth(fn):
    def inner(self, *args):
        res = get_user_by_credentials(self, fn, args, callback=done_auth)
    return inner

def get_user_by_credentials(self, fn, callback):

    def onFetchUserCredentials(result, error):
        self.user = result
        callback(self, fn, args)

    email = self.get_argument("email")
    password = self.get_argument("password")
    settings.DB.users.find_one({'email': email, 'password': password }, callback=onFetchUserCredentials)

def done_auth(result, fn, args):
    return fn(result, args)

EDIT :

Updated code to working version.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:44:55+00:00Added an answer on June 14, 2026 at 11:44 pm

    I thought at first that the problem was quite simple, but then you posted a traceback contradicting the original error message. However, I think the problem is still pretty straightforward, assuming that the traceback error is the correct one. Recall that this:

    @decorator
    def foo(x):
        return x + 1
    

    Is simply syntactic sugar for this:

    def foo(x):
        return x + 1
    foo = oauth_machine.auth(foo)
    

    So when you use @oauth_machine.auth on get, it’s passed via a closure into inner as fn.

    def auth(fn):
        def inner(self):
            res = get_user_by_credentials(self, fn, callback=done_auth)
        return inner
    

    It’s then passed into get_user_by_credentials, again as fn, which in turn produces another closure, which passes fn to callback.

    def get_user_by_credentials(self, fn, callback):
    
        def onFetchUserCredentials(result, error):
            self.user = result
            callback(self, fn)
    

    callback was defined as done_auth back in inner, so that menas that fn (i.e. the original get) is passed there, and then called on result:

    def done_auth(result, fn):
        return fn(result)
    

    But fn (i.e. get) takes two arguments. You pass it only one, causing an error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written this code in JavaScript and works perfectly fine when I include
I have written a script to parse an email. It works fine when receiving
Suppose I have written a decorator that does something very generic. For example, it
I have a rather complex decorator written by someone else. What I want to
So I've written this code for a sliding menu, only I'm having one problem,
I have written one css as foolows: <style> #box_1 #box1_bg{ width: 100px; padding-left:0px; font-family:
I have this all written out, and it all works perfectly, except for the
have written this little class, which generates a UUID every time an object of
I have written a bash script which installs a number of packages, however for
I have written this code inside a servlet to delete certain records from three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.