我的telnetlib导入错了吗?

时间:2018-01-23 16:49:22

标签: python python-3.x telnetlib

此代码出现问题:

    from telnetlib import Telnet

class doTelnet:

def login(self):
        # Configure login variables for input
        self.user = self.user.encode('ascii') + b'\n'
        self.password = self.password.encode('ascii') + b'\n'
        self.terminal_type = self.terminal_type.encode('ascii') + b'\n'

        # Do login
        # TODO Add functionality for user control of expected login prompt (some servers send 'Username: ', I'm sure theres other options)
        self.telnet.read_until('login: ')
        self.telnet.write(self.user)
        self.telnet.read_until('Password: ')
        try:
            self.telnet.write(self.password)
            print('[*]\tSuccessfully authenticated to {0}:{1}'.format(self.host, self.port))
            self.login_status = 1
        except Exception as self.e:
            print('[!]\tError authenticating to {0}:{1}\n{2}'.format(self.host, self.port, self.e)

        # Set terminal type
        self.telnet.write(self.terminal_type)

它始终在“self.telnet.write”部分失败,我无法理解为什么会这样。任何人都是精灵?

File "C:\Users\user\Downloads\CiscoIOSSNMPToolkit\doTelnet.py", line 45
    self.telnet.write(self.terminal_type)
       ^
SyntaxError: invalid syntax

错误。

https://github.com/GarnetSunset/CiscoIOSSNMPToolkit/blob/master/doTelnet.py

1 个答案:

答案 0 :(得分:0)

您在异常块中的print语句末尾缺少一个括号,这就是您抛出当前语法错误的原因。