Search code examples
python-2.7webapp2

Too many parameters error, but called with correct amount


got a question about this error:

TypeError: rot13() takes exactly 1 argument (2 given)

Which occurs on this code:

def get(self): <-- called on every get request
    ch = self.rot13("abc")

def rot13(input): <-- fairly untested rot 13 ;)
    alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
         'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    escaped = escape(input)
    ciphered = ""
    for char in escaped:
        originalIndex = alpha.index(char)
        newIndex = (originalIndex + 13) % 26
        ciphered = chipered + alpha[newIndex]

Do not know why there is this error. I'm just handing one parameter there.


Solution

  • It seems that you're missing this:

    def rot13(self, input):
    

    … That's because rot13() appears to be a method inside a class, not a stand-alone function, so it needs to receive self.