Argument count mismatch

R

RVince

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
 
C

Chris Angelico

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
 
J

John Gordon

In said:
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.
 
W

Westley Martínez

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.
 
S

Steven D'Aprano

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
 
D

Daniel Kluev

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top