Reputation: 581
I am just a beginner using python 2.7 . Please forgive my naive- ness
my following code is not working
import sys
import os
import time
import re
import pxssh
a = ['192.168.50.11', '192.168.50.12']
for i in a:
Host = i
print Host
User = "xyz"
Password = "abc"
tn = pxssh.pxssh(Host)
tn.read_until("login as: ")
tn.write(User + "\n")
tn.read_until("Password: ")
tn.write(Password + "\n")
tn.read_until("#")
tn.write("show run\n")
time.sleep(3)
output = tn.read_all()
time.sleep(3)
f = open("C:/Python27/file/"+ Host + ".txt", "w+")
f.write(output)
f.close()
tn.close()
it gives me following error :
Traceback (most recent call last):
File "C:/Python27/backup_config_files", line 5, in <module>
import pxssh
ImportError: No module named pxssh
Please let me know how can i resolve this pxssh module issue with python 2.7 in windows
Upvotes: 0
Views: 2683
Reputation: 312
This question is similar to this one.
pxssh
is a class, that you must import from the module pexpect
.
Your import would look like:
from some.location.pexpect import pxssh
If you do not have the pexpect
module, pip install pexpect
in bash in your working environment.
Upvotes: 1
Reputation: 9931
Install pexpect using
pip install pexpect
Then import using
from pexpect import pxssh
Refs: docs
Upvotes: 1