0

I returned to some old code (not that old - circa 6 months) and all of a sudden I'm getting a rather inexplicable error. What makes it particularly surprising is that this is not in my code - it's in the copy of the stdlib that goes with my Jython install, which I have not touched in any way (and which is local to my machine, so nobody else has touched it either).

To top it off the offending code looks completely innocuous to me. It's in standard imaplib.py, and it looks unproblematic. The error I get is:

  File "C:\jython2.5.3\Lib\imaplib.py", line 504, in login
    return login(user, password)
   NameError: global name 'login' is not defined

And the code is:

def login(self, user, password):
    """Identify client using plaintext password.

    (typ, [data]) = <instance>.login(user, password)

    NB: 'password' will be quoted.
    """
    typ, dat = self._simple_command('LOGIN', user, self._quote(password))
    if typ != 'OK':
        self.error(dat[-1])
        time.sleep(15)
        return login(user, password)
    self.state = 'AUTH'
    return typ, dat

That's just a vanilla recursion, yes?

Any thoughts on how to sherlock this? I'm pretty stumped.

theodox
  • 12,028
  • 3
  • 23
  • 36

2 Answers2

0

Instead of:

return login(user, password)

use:

return self.login(user, password)

(use method, not global function)

Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
  • Thanks for the help. The code is from the stdlib file, I'm a little reluctant to change it for that reason. It looks like the real culprit was a changed backend (see answer below). But thanks for the help. – theodox Apr 21 '14 at 04:45
  • So your suggestion about "vanilla recursion" is not correct. `self` as 1st argument shows that `login()` is a method. If you call `return login(user, password)` you call different `login()` which is function. – Michał Niklas Apr 22 '14 at 07:50
0

I finally found the underlying problem. It turned out that somebody had changed the authentication policy for the account, so that google was not allowing login even with correct credentials. I have not gone into detail as to why the name 'login' is undefined in this scenario, but I do know that setting up the correct access on our google account eliminated the problem.

theodox
  • 12,028
  • 3
  • 23
  • 36