我一直在尝试使用以下代码从服务器读取输出:
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname, port, username, password)
command = 'xe vm-list'
(stdin, stdout, stderr) = s.exec_command(command)
output = stdout.read()
x = output.replace("\n", ",").strip()
print(x)
s.close()
当运行“ x = output.replace(“ \ n”,“,”)。strip()“行时,” TypeError:需要一个类似字节的对象,而不是'str'“。
我究竟做错了什么?
您必须解码bytes对象以获取字符串。去做这个:
output = stdout.read().decode("UTF-8")
在其中用您的远程计算机的编码替换UTF-8。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句