PyEZ Device connection returns ConnectRefusedError.
>>> dev = Device(host='xx.xxx.xx.xx', user='xxxx',password='xxxx')
>>> dev.open()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\jnpr\junos\device.py", line 459, in open
raise EzErrors.ConnectRefusedError(self)
jnpr.junos.exception.ConnectRefusedError: ConnectRefusedError(xx.xxx.xx.xx)
It looks like netconf is not enabled on the given device. (hence PyEZ is not able to connect to netconf default 830 port).
We have 2 option
Enable netconf on device using below config command
"set system services netconf ssh"
Or pass port=22 in device class, so that PyEZ uses sh port to communicate in place of netconf 830 port.
dev = Device(host='xx.xx.xx.xxx', user='xxx', password='xxxx', port=22)
Related
I have two nearly identical devices. spur will connect via ssh with one, but not the other. How do I figure out why?
>>> shell1 = spur.SshShell('10.201.140.242', 'username', 'password', missing_host_key=spur.ssh.MissingHostKey.accept)
>>> results = shell1.run(['ls', '-a'])
>>> results.output
'.\n..\n.aptitude\n.bashrc\n.cache\n.config\n.profile\n'
>>> shell2 = spur.SshShell('10.201.129.56', 'username', 'password', missing_host_key=spur.ssh.MissingHostKey.accept)
>>> results = shell2.run(['ls', '-a'])
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "E:\development\virtenv\lib\site-packages\spur\ssh.py", line 166, in run
return self.spawn(*args, **kwargs).wait_for_result()
File "E:\development\virtenv\lib\site-packages\spur\ssh.py", line 178, in spawn
channel = self._get_ssh_transport().open_session()
File "E:\development\virtenv\lib\site-packages\spur\ssh.py", line 268, in _get_ssh_transport
raise self._connection_error(error)
ConnectionError: Error creating SSH connection
Original error: ('10.201.129.56', <paramiko.ecdsakey.ECDSAKey object at 0x11328070>, <paramiko.ecdsakey.ECDSAKey object at 0x1135F350>)
I'm confused by the error message. What does returning the ip, and two key objects supposed to mean? Is there helpful info here I'm supposed to glean from that?
Both devices will accept ssh connections from the command line, so that sets aside an obvious problem.
Both are running the same version of Ubuntu, with the same login credentials. Home directories are even the same (no .ssh dir). Even further, both of their sshd_config files are identical (so, also using the same version among other config options).
The problem doesn't seem to be in the ssh settings, but the error gives no indication of where the problem could be!
Any ideas?
Enabling logging doesn't add much.
shell1:
11:32:11|[ INFO] - paramiko.transport - _log - Connected (version 2.0, client OpenSSH_5.9p1)
11:32:11|[ INFO] - paramiko.transport - _log - Authentication (password) successful!
shell2:
11:32:25|[ INFO] - paramiko.transport - _log - Connected (version 2.0, client OpenSSH_5.9p1)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "E:\development\virtenv\lib\site-packages\spur\ssh.py", line 166, in run
return self.spawn(*args, **kwargs).wait_for_result()
File "E:\development\virtenv\lib\site-packages\spur\ssh.py", line 178, in spawn
File "E:\development\virtenv\lib\site-packages\spur\ssh.py", line 268, in _get_ssh_transport
raise self._connection_error(error)
ConnectionError: Error creating SSH connection
Original error: ('10.201.129.56', <paramiko.ecdsakey.ECDSAKey object at 0x1132EF10>, <paramiko.ecdsakey.ECDSAKey object at 0x11366DF0>)
It might be telling that the SSH reports connection. The failure occurs before/during authentication. But as I said above, the passwords are the same -- both connections even use the same copy-pasted pw, which works without error on a command line connection.
Is there any way available to check the status of a apache tomcat server from another machine in python?
For example, A restful API is running in a machine with apache tomcat server in 8086 port.
Now, what I want is to check the status of the apache tomcat service of the specified machine from my pc programmatically in python.
Yes,I could check the machine is running or not through pinging by using os.system in python.
import os
hostname = "xxx.xxx.xxx.xxx" #example
response = os.system("ping -c 1 " + hostname)
#and then check the response...
if response == 0:
print hostname, 'is up!'
else:
print hostname, 'is down!'
But, what I am interested in is that, is it possible to check the status of the service (real_ip:8086/BotAPI) in stead of the liveness of the machine, programmatically in python ?
Update: using paramiko I got the following traceback
channel.exec_command('ps -ef| grep tomcat')
Traceback (most recent call last):
File "<pyshell#67>", line 1, in <module>
channel.exec_command('ps -ef| grep tomcat')
File "E:\python\lib\site-packages\paramiko\channel.py", line 63, in _check
return func(self, *args, **kwds)
File "E:\python\lib\site-packages\paramiko\channel.py", line 241, in exec_command
self._wait_for_event()
File "E:\python\lib\site-packages\paramiko\channel.py", line 1197, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
You could use fabric or paramiko to connect remotely to your tomcat machine and then check if the process is running
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('hostname', username='user', password='password')
transport = ssh.get_transport()
channel = transport.open_session()
channel.exec_command('ps -ef | grep tomcat')
status = channel.recv_exit_status()
I'm using Python's Paramiko to execute commands in a remove server. The code is much simple.
Here's my definition of the SSHConn class:
class SSHConn:
def __init__(self, hostname, user, pwd, filename=None):
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.client.connect(hostname, username=user, password=pwd,
key_filename=filename)
self.transport = self.client.get_transport()
self.channel = self.transport.open_session()
So I'm running the following code:
local_ssh = ssh.SSHConn(host, user, passwd)
cmds = ('foo', 'bar')
for cmd in cmds:
local_ssh.channel.exec_command(cmd)
self.log.info(local_ssh.channel.recv(1024))
However, when I execute the following code snipped I'm getting:
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_6.6.1p1)
INFO:paramiko.transport:Authentication (publickey) failed.
INFO:paramiko.transport:Authentication (password) successful!
INFO:paramiko.transport:Secsh channel 1 opened.
INFO:testsets.testcase:
ERROR:testsets.testcase:Channel is not open
Traceback (most recent call last):
File "/root/fds-src/source/test/integration-framework/testsets/testcases/test_100gb_volume.py", line 87, in runTest
local_ssh.channel.exec_command(cmd)
File "/usr/lib/python2.7/dist-packages/paramiko/channel.py", line 209, in exec_command
raise SSHException('Channel is not open')
SSHException: Channel is not open
ERROR:testsets.testcase:Test Case Test100GBVolume failed.
Traceback (most recent call last):
File "/root/fds-src/source/test/integration-framework/testsets/testcases/test_100gb_volume.py", line 87, in runTest
local_ssh.channel.exec_command(cmd)
File "/usr/lib/python2.7/dist-packages/paramiko/channel.py", line 209, in exec_command
raise SSHException('Channel is not open')
SSHException: Channel is not open
How can I keep the channel open?
The channel docs are very clear about this point. You need to open a new channel for each exec_command.
exec_command(*args, **kwds)
Execute a command on the server. If the server allows it, the channel will then be directly connected to the stdin, stdout, and stderr of the command being executed.
When the command finishes executing, the channel will be closed and can’t be reused. You must open a new channel if you wish to execute another command.
The SSHClient object has an exec_command method that does this for you.
I'm trying to connect to MQ z/OS using PYMQI, but I get the following error:
Traceback (most recent call last):
File "davidemq.py", line 9, in <module>
qmgr = pymqi.connect(queue_manager, channel, conn_info)
File "/usr/local/lib/python2.7/dist-packages/pymqi.py", line 2431, in connect
qmgr.connect_tcp_client(queue_manager, CD(), channel, conn_info)
File "/usr/local/lib/python2.7/dist-packages/pymqi.py", line 1330, in connectTCPClient
self.connectWithOptions(name, cd)
File "/usr/local/lib/python2.7/dist-packages/pymqi.py", line 1311, in connectWithOptions
raise MQMIError(rv[1], rv[2])
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2195: FAILED: MQRC_UNEXPECTED_ERROR
This is the code:
import pymqi
queue_manager = "****"
channel = "***********"
host = "******"
port = "nnnnn"
conn_info = "%s(%s)" % (host, port)
qmgr = pymqi.connect(queue_manager, channel, conn_info)
Your traceback gives you the (vague) error:
Reason 2195: FAILED: MQRC_UNEXPECTED_ERROR
Could be an environment/configuration error, permissions, missing something from the classpath.
See:
why i am getting websphere mq error code 2195 where my adapter read a messages from websphere mq
How to resolve WebSphere MQ Reason code 2195 related error?
I created a VSP using SOCAT with below command:
socat -d -d pty,raw,echo=0 pty,raw,echo=0
where I was able create a serial device (19200,N,8,1) and send and receive data using Python.
So I have to do the same for one more device with config of (19200,even_aprity,hardware flow in Python) when I do that its throwing below error:
Traceback (most recent call last):
File "py2.py", line 163, in <module>
buffer += ser.read(1) # this will block until one more char or timeout
File "/usr/lib/python2.6/dist-packages/serial/serialposix.py", line 311, in read
if self.fd is None: raise portNotOpenError
serial.serialutil.SerialException: Port not open
Exception SystemError: 'error return without exception set' in <bound method BreakHandler.__del__ of <sig_handler.BreakHandler instance at 0xb719338c>> ignored
Guide me