TypeError:“在<string>中,通过python telnet发送cmd

2024-05-14 18:57:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过python telnet发送ls /cmd

import telnetlib
tel = telnetlib.Telnet('10.10.0.1'.'1234')
tel.write('ls / ')

但我有一个错误:

if IAC in buffer:
TypeError: 'in <string>' requires string as left operand, not bytes

Tags: inimportcmdstringifbuffer错误ls
1条回答
网友
1楼 · 发布于 2024-05-14 18:57:49

您需要将字符串编码为ASCII:

tel.write(('ls / ').encode('ascii'))

在Python3中,str类将字符串存储为unicode,您需要显式地将它们转换为ascii。基本上,您需要一个字节字符串,其中每个字符都是ASCII字符,而不是Unicode字符

相关问题 更多 >

    热门问题