Not able to take ssh of a device using python getting below error.
Tried reinstalling python paramiko but didnt worked
import paramiko
import sys
import time
paramiko.client.SSHClient()
HOST = "192.168.1.11"
USER = "cisco"
PASS = "cisco"
client1=paramiko.SSHClient()
client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client1.connect(HOST,username=USER,password=PASS)
print "SSH connection to %s established" %HOST
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/testssh.py", line 1, in
import paramiko
File "C:\Python27\lib\site-packages\paramiko__init__.py", line 31, in
from paramiko.client import SSHClient, MissingHostKeyPolicy, AutoAddPolicy, RejectPolicy, WarningPolicy
File "C:\Python27\lib\site-packages\paramiko\client.py", line 24, in
import getpass
File "C:/Users/Administrator/Desktop\getpass.py", line 11, in
remote_conn_pre=paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'
Change this
client1=paramiko.SSHClient()
to this
client1=paramiko.client.SSHClient()
Your best clue is the last line of the stack trace:
line 11, in remote_conn_pre=paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'
(Added some whitespace for clarity)
Here it is saying that on this line, it can't find the property SSHClient in the paramiko class.
I would say to check the paramiko documentation, but you can see that you have successfully called this function on line 4:
paramiko.client.SSHClient()
Which will probably also work on line 11 - as other answers have pointed out, you need to access it through paramiko.client, not just paramiko. You probably also don't need line 4.
Related
I have this python code which getting data from socket's and printing to console. But in working process I getting this error code
Traceback (most recent call last):
File "server.py", line 1, in <module>
import ssl, socket
File "/home/ssl.py", line 20, in <module>
returned from time.time())
AttributeError: 'module' object has no attribute 'wrap_socket'
maybe somebody has any idea how I can fix this issue?
import ssl, socket
sock = ssl.wrap_socket(socket.socket(), 'server.key', 'server.crt', True)
sock.bind( ('', 443) )
sock.listen(10)
while True:
conn, addr = sock.accept()
data = conn.recv(4)
print data
thank you
You most likely have a file named ssl.py in the same directory, as indicated by this part of the error:
File "/home/ssl.py", line 20, in
returned from time.time())
and the script is trying to import that instead of the system level module. If you cannot change the name of that file, try using absolute and relative imports.
I want to transfer files between two Ubuntu Servers using scp, i have tested scp between the two systems and it worked perfectly fine.So i dont want to execute the command everytime i need to get files so i want to write a python script which automatically downloads files from other host using scp.
While searching online i found this Paramiko module and i have trouble installing this and i have rectified this using module cryptography.Now the real trouble is explained with the terminal below.
>>> from paramiko import SSHClient
>>> from scp import SCPClient
>>> ssh = SSHClient()
>>> ssh
<paramiko.client.SSHClient object at 0x1a41c90>
>>> ssh.load_system_host_keys()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect('somename#192.168.100.100')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 296, in c onnect
to_try = list(self._families_and_addresses(hostname, port))
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 200, in _ families_and_addresses
addrinfos = socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_S TREAM)
socket.gaierror: [Errno -2] Name or service not known
>>> ssh.connect('192.168.100.100')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 361, in c onnect
server_key)
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 672, in m issing_host_key
raise SSHException('Server %r not found in known_hosts' % hostname)
paramiko.ssh_exception.SSHException: Server '192.168.100.100' not found in known_hos ts
I have changed the ip and username for safe use somename is replaced but i have tried with original username.So i tried this several times but i still getting the same error.
Any suggestions on this problem?Please Help.
Maybe you are missing the missing_host_key_policy
What about this one:
proxy = None
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host['hostname'], username=host['user'], sock=proxy)
more examples here: www.programcreek.com
For me the solution was:
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(host, username=user,password=password)
Try using this:
ssh.connect('host', username='username',password='password')
You can also add your public key to known hosts in server, if you wish to skip password and connect without giving your password.
In that case use:
ssh.connect('host', username='username')
I'm trying to use paramiko for SSH, but got an error:
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect('54.***.***.110', key_filename='D:\Keys\MyOWN\priv.ppk')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win32\egg\paramiko\client.py", line 366, in connect
File "build\bdist.win32\egg\paramiko\client.py", line 515, in _auth
File "build\bdist.win32\egg\paramiko\agent.py", line 343, in __init__
File "build\bdist.win32\egg\paramiko\agent.py", line 66, in _connect
File "build\bdist.win32\egg\paramiko\agent.py", line 83, in _send_message
File "build\bdist.win32\egg\paramiko\win_pageant.py", line 123, in send
File "build\bdist.win32\egg\paramiko\win_pageant.py", line 89, in _query_pageant
File "build\bdist.win32\egg\paramiko\_winapi.py", line 273, in get_security_attributes_for_user
File "build\bdist.win32\egg\paramiko\_winapi.py", line 222, in descriptor
NameError: global name 'descriptor' is not defined
Regarding this issue - it was solved, but - I still have this error (latest paramiko version, downloaded from it's Github).
May be - there is some other libs, to wok via SSH with RSA-key authorization?
Or - any way to solve this NameError...
Seems like the issue is not really solved (I too downloaded latest zip: it can also be seen on [GitHub]: paramiko/paramiko - (v1.15.2) paramiko/paramiko/_winapi.py), so you'll have to fix it yourself in your paramiko installation files (fixed in v1.15.3):
Edit your ${PYTHON_DIR}\build\bdist.win32\egg\paramiko\_winapi.py (${PYTHON_DIR} is just a placeholder for your Python installation directory),
and at lines 222 and 223 simply replace descriptor by value:
self._descriptor = descriptor
self.lpSecurityDescriptor = ctypes.addressof(descriptor)
should become:
self._descriptor = value
self.lpSecurityDescriptor = ctypes.addressof(value)
I used to get this type of errors. I restarted the machine and it got solved!
But I think there is a bug in the paramiko library.
Changing descriptor by value as explained by CristiFati works fine.
I met the issue too, please try to set the allow_agent=False, and it should be resolved.
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('54.***.***.110', key_filename='D:\Keys\MyOWN\priv.ppk', allow_agent=False)
I am trying to connect to some router using the above code and I am using juniperj2320.py module and in test file I have
am using code base from this http://subversion.assembla.com/svn/clauzsistel08/trunk/dist/
#!/usr/bin/python
from localconf import *
from juniperj2320 import *
import sys
import traceback
SERIALDEVICE = '/dev/ttyUSB0'
# Now configure the router
try:
router = JuniperJ2320(SERIALDEVICE)
except RouterConfigurationException, err:
print "Router configuration error: ", err
print "Please try again."
sys.exit(1)
but am getting this following error
./test.py
> /root/pyserial-2.6/examples/serialrouter.py(37)__init__()
-> serial.Serial.__init__(self, serialdevice, baudrate=baudrate, \
(Pdb) c
Traceback (most recent call last):
File "./test.py", line 30, in
router = JuniperJ2320(SERIALDEVICE)
File "/root/pyserial-2.6/examples/juniperj2320.py", line 32, in __init__
BYTESIZE, PARITY, STOPBITS, TIMEOUT)
File "/root/pyserial-2.6/examples/serialrouter.py", line 44, in __init__
fdpexpect.fdspawn.__init__(self, self.fileno())
File "/usr/lib/python2.6/site-packages/fdpexpect.py", line 40, in __init__
spawn.__init__(self, None, args, timeout, maxread, searchwindowsize, logfile )
File "/usr/lib/python2.6/site-packages/pexpect.py", line 412, in __init__
self.closed = True # File-like object.
AttributeError: can't set attribute
and absolutely clue less on wat happening here ! any help ll be greatly appreciated
thanks
This is a little bit of a shot in the dark, because I'm not familiar with the modules you're using, but based on the traceback, it looks like the constructor is expecting a file-like object, not just a file path. Try this instead.
SERIALDEVICE = '/dev/ttyUSB0'
# Now configure the router
try:
router = JuniperJ2320(open(SERIALDEVICE))
Instead of writing your own serial communications program wouldn't be easier to have pexpect drive a serial program like minicom?
I'm creating a very simple example on OSX with python 2.6 but I keep getting:
Traceback (most recent call last):
File "ssl.py", line 1, in <module>
import socket, ssl
File "/Users/Dennis/ssl.py", line 5, in <module>
sslSocket = ssl.wrap_socket(s)
AttributeError: 'module' object has no attribute 'wrap_socket'
Code:
import socket, ssl
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('irc.freenode.net', 7000))
sslSocket = ssl.wrap_socket(s)
print repr(sslSocket.server())
print repr(sslSocket.issuer())
sslSocket.write('Hello secure socket\n')
s.close()
What am I doing terribly wrong?
Thanks!
Dennis
Don't name your script ssl.py, because when you name your script ssl.py and you do import ssl you're importing this same script .
Your script is : ssl.py
When you do an import ssl, it calls itself and that is why you get the AttributeError
Give another name to your script and it should work.