python3 winpexpect问题请教
代码如下(前置条件为: windows系统 python3.4 winpexpect版本是1.5)为了验证,所以简化代码,expect匹配都去掉了。import winpexpect
import sys
hostip = '172.18.24.1'
print ('00')
hostcmd = 'telnet ' + hostip
print ('001')
child = winpexpect.winspawn(hostcmd)
print ('002')
username = 'root'
time.sleep(1)
#username = username.encode('utf-8')
child.sendline(username)
print ('1')
time.sleep(1)
child.sendline('123456')
child.logfile = sys.stdout
运行结果是
>>> ================================ RESTART ================================
>>>
00
001
002
Traceback (most recent call last):
File "C:\Users\A103\Desktop\pex2.py", line 17, in <module>
child.sendline(username)
File "C:\Python34\lib\site-packages\winpexpect-1.5-py3.4.egg\pexpect.py", line 961, in sendline
n = self.send(s)
File "C:\Python34\lib\site-packages\winpexpect-1.5-py3.4.egg\pexpect.py", line 953, in send
c = os.write(self.child_fd, s.encode('ascii'))
OSError: [Errno 22] Invalid argument
>>>
尝试编码转换过,无效(例如username = username.encode('utf-8')或者decode('')等等
请教各位大神,如何解决。