When I run the following code, i'm receiving just <pexpect.popen_spawn.PopenSpawn object at 0x029678F0>
import pexpect
from pexpect import popen_spawn
import sys
co = pexpect.popen_spawn.PopenSpawn('ftp localhost',encoding="utf-8")
co.expect("",timeout=30)
co.logfile = sys.stdout
co.timeout = 4
co.expect(":")
co.sendline("test")
co.expect(".*word:.*")
co.sendline("test123")
co.sendline('dir')
co.expect('ftp>')
co.close()
except Exception as e:
print(co)
That probably means that encoding='utf-8'
is not the right option for your system or for that subprocess. What system are you on? If it's Windows, the encoding might be 'cp1252' (that's the default for western European languages, in any case).
Do you need to have the try/except to catch the exception? If there's an uncaught exception, it's automatically printed out with a traceback, which is more helpful for debugging.