Argument count mismatch

Discussion in 'Python' started by RVince, Apr 21, 2011.

  1. RVince

    RVince Guest

    I am getting the following:

    Error - <type 'exceptions.TypeError'>: cmseditorlinemethod() takes
    exactly 2 arguments (1 given)

    When I make the following call:

    http://localhost/eligibility/cmseditorlinemethod/474724434

    Which invokes:

    def cmseditorlinemethod(self, ssn):
    c.details =
    Session.query(MSPResponse).filter(MSPResponse.beneficiaryssn ==
    ssn).all()
    content = render('/cmseditorline.mako')
    return content

    Can anyone tell me what the mismatch is in the number of my parameters
    based on this? Thanks, RVince
     
    RVince, Apr 21, 2011
    #1
    1. Advertising

  2. Wolfgang Rohdewald, Apr 21, 2011
    #2
    1. Advertising

  3. On Fri, Apr 22, 2011 at 5:33 AM, RVince <> wrote:
    > I am getting the following:
    >
    > Error - <type 'exceptions.TypeError'>: cmseditorlinemethod() takes
    > exactly 2 arguments (1 given)
    >
    > When I make the following call:
    >
    > http://localhost/eligibility/cmseditorlinemethod/474724434
    >
    > Which invokes:
    >
    > def cmseditorlinemethod(self, ssn):


    You're doing an HTTP request that ultimately is supposed to translate
    into a method call. The problem appears to be somewhere in between
    those; what system are you using to handle HTTP (web) requests, and
    how does it translate a URL into a method call?

    As a side point, if it takes a piece of the URL and looks it up,
    unchecked, as a member name, this is a rather dodgy practice. I hope
    you have a whitelist of legal method names.

    Chris Angelico
     
    Chris Angelico, Apr 21, 2011
    #3
  4. RVince

    John Gordon Guest

    In <> RVince <> writes:

    > def cmseditorlinemethod(self, ssn):
    > c.details =
    > Session.query(MSPResponse).filter(MSPResponse.beneficiaryssn ==
    > ssn).all()
    > content = render('/cmseditorline.mako')
    > return content


    Is cmseditorlinemethod() a member of a class? The presence of the "self"
    parameter suggests that it is, but your code omits this detail.

    --
    John Gordon A is for Amy, who fell down the stairs
    B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"
     
    John Gordon, Apr 21, 2011
    #4
  5. On Thu, Apr 21, 2011 at 12:33:09PM -0700, RVince wrote:
    > I am getting the following:
    >
    > Error - <type 'exceptions.TypeError'>: cmseditorlinemethod() takes
    > exactly 2 arguments (1 given)
    >
    > When I make the following call:
    >
    > http://localhost/eligibility/cmseditorlinemethod/474724434
    >
    > Which invokes:
    >
    > def cmseditorlinemethod(self, ssn):
    > c.details =
    > Session.query(MSPResponse).filter(MSPResponse.beneficiaryssn ==
    > ssn).all()
    > content = render('/cmseditorline.mako')
    > return content
    >
    > Can anyone tell me what the mismatch is in the number of my parameters
    > based on this? Thanks, RVince


    There's no way to see that link without knowing a domainname or IP.
    localhost only works locally, go figure, but regardless I'd suspect that
    you need to give two arguments instead of one, considering that's what
    the error message said.
     
    Westley Martínez, Apr 21, 2011
    #5
  6. On Thu, 21 Apr 2011 12:33:09 -0700, RVince wrote:

    > I am getting the following:
    >
    > Error - <type 'exceptions.TypeError'>: cmseditorlinemethod() takes
    > exactly 2 arguments (1 given)
    >
    > When I make the following call:
    >
    > http://localhost/eligibility/cmseditorlinemethod/474724434


    That's not a call, that's a URL. It's also a link to localhost, which is
    *your* computer and not visible to us.

    How about actually showing us the *actual call* you make? Cut and paste
    the line of code that calls cmseditorlinemethod, showing the arguments.

    My *guess* is that you're calling it without providing any arguments:

    instance.cmseditorlinemethod()

    Python automatically injects the `self` argument, but it requires two:
    self and ssn:

    > def cmseditorlinemethod(self, ssn):

    [...]


    An alternative explanation: you don't use `self` in the body of
    cmseditorlinemethod. Possibly cmseditorlinemethod is actually a stand-
    alone function rather than a method, and you are calling it like this:

    cmseditorlinemethod(ssn)

    but you have mistakenly declared the function to take two arguments.

    Really, the error message is quite explicit in your problem: you have one
    argument given, but two arguments are required. The only subtlety is that
    for method calls, the `self` argument is automatically provided rather
    than manually, but once you've learned that quirk of Python, what else do
    you need to know to solve this problem?

    By the way, I know this is unsolicited advice, but I'm going to give it
    anyway. Look at your function:


    def cmseditorlinemethod(self, ssn):
    c.details = Session.query(MSPResponse).filter(
    MSPResponse.beneficiaryssn == ssn).all()
    content = render('/cmseditorline.mako')
    return content


    It looks to me like this function relies on no fewer than three global
    variables, two that you read from and one which you write to:

    c
    Session
    MSPResponse

    This is almost certainly poor design. Using global state is almost always
    harmful and should be avoided.

    (I don't include `render` in this, as using global functions is normally
    harmless.)

    http://c2.com/cgi/wiki?GlobalVariablesAreBad



    --
    Steven
     
    Steven D'Aprano, Apr 22, 2011
    #6
  7. RVince

    Daniel Kluev Guest

    On Fri, Apr 22, 2011 at 12:43 PM, Steven D'Aprano
    <> wrote:
    > It looks to me like this function relies on no fewer than three global
    > variables, two that you read from and one which you write to:
    >
    > c
    > Session
    > MSPResponse
    >
    > This is almost certainly poor design. Using global state is almost always
    > harmful and should be avoided.


    Looks like its something similar to Pylons web framework. While
    generally globals vars are indeed bad, in this case they are
    specifically provided by framework to be used this way.
    They are 'thread-local' rather than global, and usually cause no harm,
    since framework guarantees that these instances are bound to context
    of this particular http request.

    --
    With best regards,
    Daniel Kluev
     
    Daniel Kluev, Apr 22, 2011
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Novice
    Replies:
    1
    Views:
    1,168
    Mike Schilling
    Jul 19, 2003
  2. Dave
    Replies:
    2
    Views:
    438
    Martin Eisenberg
    Apr 5, 2004
  3. Replies:
    1
    Views:
    292
    Alex Martelli
    Dec 20, 2005
  4. Clarence
    Replies:
    0
    Views:
    422
    Clarence
    Apr 10, 2007
  5. efelnavarro09
    Replies:
    2
    Views:
    948
    efelnavarro09
    Jan 26, 2011
Loading...

Share This Page