The telnet protocol includes special characters to send telnet control sequences between the client and the server. Your 'telnet' command most likely sends these characters. You may be able to see them by printing repr(username), repr(password) instead of username and password for example. I don't think you can succeed without learning the telnet protocol first, but... a simpler alternative is to google 'telnet server in python' and browse or download the resulting existing attempts to implement this protocol.
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691