I have this python script that uses pxssh. Here's the script:
from pexpect import pxssh import getpass try: s = pxssh.pxssh() hostname = input('hostname: ') username = input('username: ') password = getpass.getpass('password: ') s.login(hostname, username, password) s.sendline('cat hiera/my.yaml') # run a command s.prompt() # match the prompt for line in s.before.splitlines()[1:]: print (line) s.logout() except pxssh.ExceptionPxssh as e: print("pxssh failed on login.") print(e)
and I cannot understand why the script output looks like this:
b'---' b'settings_prod: |' b'"""' b"Generated by 'django-admin startproject' using Django 2.0.5." b'' b'For more information on this file, see' b'https://docs.djangoproject.com/en/2.0/topics/settings/' b'' b'For the full list of settings and their values, see' b'https://docs.djangoproject.com/en/2.0/ref/settings/' b'"""'
What is up with the
b' at the start of each line and the
' on the end of each line of output? How do I get rid if it?
From the docs:
Bytes literals are always prefixed with 'b' or 'B'; they produce an instance of the bytes type instead of the str type. They may only contain ASCII characters; bytes with a numeric value of 128 or greater must be expressed with escapes.