[Twisted-Python] Re : Re : Re : Telnet server using Twisted and AuthenticatingTelnetProtocol

filoufake-python at yahoo.fr filoufake-python at yahoo.fr
Wed Sep 2 07:44:16 EDT 2009


>It's hard to say what's going wrong without being able to see all of the 
>code.  A short, self contained, correct example (<http://sscce.org/>) 
>would help a lot.

Hereafter is the simplest code that generates the problem.
If you run it, you will see that after entering the password nothing
happened. The "telnet_Command" method of MyTelnet is never called.
I think the problem is what requestAvatar returns.
Thanks again for your support

import sys
from zope.interface import implements
from twisted.internet import protocol
from twisted.python import log
from twisted.cred import error
from twisted.cred import portal
from twisted.cred import checkers
from twisted.cred import credentials
from twisted.conch.telnet import AuthenticatingTelnetProtocol
from twisted.conch.telnet import StatefulTelnetProtocol
from twisted.conch.telnet import ITelnetProtocol
from twisted.conch.telnet import TelnetTransport

class Realm:

  def requestAvatar(self, avatarId, mind, *interfaces):
    if ITelnetProtocol in interfaces:
      av = MyTelnet()
      return ITelnetProtocol, av, lambda:None
    raise NotImplementedError("Not supported by this realm")

class MyTelnet(StatefulTelnetProtocol):
  def telnet_Command(self, line):
    print "line received via telnet", line

def main():
  r = Realm()
  p = portal.Portal(r)
  c = checkers.InMemoryUsernamePasswordDatabaseDontUse()
  c.addUser("AA", "aa")
  f = protocol.ServerFactory()
  f.protocol = lambda: TelnetTransport(AuthenticatingTelnetProtocol, p)
  from twisted.internet import reactor
  reactor.listenTCP(4738, f)

if __name__ == '__main__':


More information about the Twisted-Python mailing list