I've been trying to read the output from a server with this code:
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()
When the line "x = output.replace("\n", ",").strip()" is run "TypeError: a bytes-like object is required, not 'str'" is thrown.
What am I doing wrong?
outputseems to be a string of bytes; you'll want to decode that to (character) string before applyingreplace- something likeoutput.decode('utf-8').replace("\n", ",").strip(), adjusted to the specific encoding. - MrFuppes