Paramiko.ssh_exception.SSHException: Channel closed - python

I just encountered the problem with connecting the SDN switch, pica 8 3290, with ryu's of-config library and python paramiko library.
Here's the traceback msg:
=================================================================================
xdn41o71:ryu Mac$ sudo ryu-manager ryu/app/of_config.py
Password:
loading app ryu/app/of_config.py
Connected (version 2.0, client OpenSSH_6.0p1)
Authentication (password) successful!
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/bin/ryu-manager", line 9, in <module>
load_entry_point('ryu==3.20.1', 'console_scripts', 'ryu-manager')()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ryu/cmd/manager.py", line 88, in main
app_mgr.load_apps(app_lists)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ryu/base/app_manager.py", line 390, in load_apps
cls = self.load_app(app_cls_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ryu/base/app_manager.py", line 366, in load_app
mod = utils.import_module(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ryu/utils.py", line 91, in import_module
__import__(name)
File "/Users/Mac/ryu/ryu/app/of_config.py", line 9, in <module>
unknown_host_cb=lambda host, fingeprint: True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ryu/lib/of_config/capable_switch.py", line 50, in __init__
self.netconf = connect(*self._connect_args, **self._connect_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ryu/contrib/ncclient/manager.py", line 67, in connect_ssh
session.connect(*args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ryu/contrib/ncclient/transport/ssh.py", line 208, in connect
c.invoke_subsystem("netconf")
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/channel.py", line 60, in _check
return func(self, *args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/channel.py", line 254, in invoke_subsystem
self._wait_for_event()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/channel.py", line 1086, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
===============================================================================
I've googled the problem, paramiko.ssh_exception.SSHException: Channel closed.,
however, there isn't any appropriate solution to my problem.
Anyone can give me some instructions to solve this problem?

Related

Cannot connect to SSH in python

I want to connect to a Linux server that is connected to my network using ssh but am getting an error
import sys
result=[]
clinet=paramiko.SSHClient()
clinet.set_missing_host_key_policy(paramiko.AutoAddPolicy())
clinet.connect('192.168.74.180',22,username="user",password='password')
ssh_stdin,ssh_stdout,ssh_stderr=clinet.exec_command('enable\r\nconnect\r\nLine 1\r\n:::01:SD*')
for line in ssh_stdout:
result.append(line.strip('\n'))
for i in result:
print(i.strip())
sys.exit()
the error that is coming is:
File "C:\Users\vishnu.n\Desktop\server\ssh.py", line 7, in <module>
ssh_stdin,ssh_stdout,ssh_stderr=clinet.exec_command('enable\r\nconnect\r\nLine 1\r\n:::01:SD*')
File "C:\Users\vishnu.n\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\client.py", line 516, in exec_command
chan.exec_command(command)
File "C:\Users\vishnu.n\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\channel.py", line 72, in _check
return func(self, *args, **kwds)
File "C:\Users\vishnu.n\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\channel.py", line 257, in exec_command
self._wait_for_event()
File "C:\Users\vishnu.n\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\channel.py", line 1226, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
PS C:\Users\vishnu.n\Desktop\server> python ssh.py
Traceback (most recent call last):
File "C:\Users\vishnu.n\Desktop\server\ssh.py", line 7, in <module>
ssh_stdin,ssh_stdout,ssh_stderr=clinet.exec_command('enable')
File "C:\Users\vishnu.n\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\client.py", line 516, in exec_command
chan.exec_command(command)
File "C:\Users\vishnu.n\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\channel.py", line 72, in _check
return func(self, *args, **kwds)
File "C:\Users\vishnu.n\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\channel.py", line 257, in exec_command
self._wait_for_event()
File "C:\Users\vishnu.n\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\channel.py", line 1226, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.

ModuleNotFoundError: No module named 'tornado' on ubuntu

When I am trying to run my application I got the following error
Traceback (most recent call last):
File "./app.py", line 32, in <module>
from pushservices.bootstrap import init_messaging_agents
File "/home/airnotifier/airnotifier/pushservices/bootstrap.py", line 2, in <module>
from .apns import *
File "/home/airnotifier/airnotifier/pushservices/apns.py", line 5, in <module>
from util import json_encode
File "/home/airnotifier/airnotifier/util.py", line 37, in <module>
import tornado
ModuleNotFoundError: No module named 'tornado'
I tried to run this command to install tornado
python3 -m pip install tornado
then I got the following message
Requirement already satisfied: tornado in /usr/local/lib/python3.8/dist-packages (6.0.3)
followed by the following error log
--- Logging error ---
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/utils/logging.py", line 177, in emit
self.console.print(renderable, overflow="ignore", crop=False, style=style)
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/console.py", line 1752, in print
extend(render(renderable, render_options))
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/console.py", line 1390, in render
for render_output in iter_render:
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/utils/logging.py", line 134, in __rich_console__
for line in lines:
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/segment.py", line 245, in split_lines
for segment in segments:
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/console.py", line 1368, in render
renderable = rich_cast(renderable)
File "/usr/local/lib/python3.8/dist-packages/pip/_vendor/rich/protocol.py", line 36, in rich_cast
renderable = cast_method()
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/self_outdated_check.py", line 130, in __rich__
pip_cmd = get_best_invocation_for_this_pip()
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/utils/entrypoints.py", line 58, in get_best_invocation_for_this_pip
if found_executable and os.path.samefile(
File "/usr/lib/python3.8/genericpath.py", line 101, in samefile
s2 = os.stat(f2)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/pip3.8'
Call stack:
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.8/dist-packages/pip/__main__.py", line 31, in <module>
sys.exit(_main())
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/cli/main.py", line 70, in main
return command.main(cmd_args)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/cli/base_command.py", line 101, in main
return self._main(args)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/cli/base_command.py", line 223, in _main
self.handle_pip_version_check(options)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/cli/req_command.py", line 148, in handle_pip_version_check
pip_self_version_check(session, options)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/self_outdated_check.py", line 237, in pip_self_version_check
logger.info("[present-rich] %s", upgrade_prompt)
File "/usr/lib/python3.8/logging/__init__.py", line 1446, in info
self._log(INFO, msg, args, **kwargs)
File "/usr/lib/python3.8/logging/__init__.py", line 1589, in _log
self.handle(record)
File "/usr/lib/python3.8/logging/__init__.py", line 1599, in handle
self.callHandlers(record)
File "/usr/lib/python3.8/logging/__init__.py", line 1661, in callHandlers
hdlr.handle(record)
File "/usr/lib/python3.8/logging/__init__.py", line 954, in handle
self.emit(record)
File "/usr/local/lib/python3.8/dist-packages/pip/_internal/utils/logging.py", line 179, in emit
self.handleError(record)
Message: '[present-rich] %s'
Arguments: (UpgradePrompt(old='22.1.2', new='22.2.2'),)
can anyone please tell me what should I do and what is the problem ?
Here's a possible scenario that could cause this:
you execute pip install tornado as a user but you run the tornado project as another user.
Sorry for my terrible english, hope you can understand

Module 'cryptography.utils' has no attribute 'bit_length'

I am currently trying to figure out how to use netmiko to automate some of my routine work.Such as getting configuration backup, creating vlans etc.I've managed to use it on Aruba and Huawei Switches without problem.But on alcatel switch I'm facing this issue:
Unknown exception: module 'cryptography.utils' has no attribute 'bit_length'
Traceback (most recent call last):
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\transport.py", line 2075, in run
self.kex_engine.parse_next(ptype, m)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\kex_gex.py", line 101, in parse_next
return self._parse_kexdh_gex_reply(m)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\kex_gex.py", line 281, in _parse_kexdh_gex_reply
self.transport._verify_key(host_key, sig)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\transport.py", line 1886, in _verify_key
if not key.verify_ssh_sig(self.H, Message(sig)):
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\dsskey.py", line 148, in verify_ssh_sig
key = dsa.DSAPublicNumbers(
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\cryptography\hazmat\primitives\asymmetric\dsa.py", line 212, in public_key
return backend.load_dsa_public_numbers(self)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 871, in load_dsa_public_numbers
dsa._check_dsa_parameters(numbers.parameter_numbers)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko\tplink\tplink_jetstream.py", line 145, in _override_check_dsa_parameters
if crypto_utils.bit_length(parameters.q) not in [160, 256]:
AttributeError: module 'cryptography.utils' has no attribute 'bit_length'
Traceback (most recent call last):
File "C:\Users\melih.celik\Desktop\New_Backup\Yedek\Coding\Rand stuff\ssh_deneme(toplu).py", line 75, in
config_backup(cihaz_secim,ip_address,username,password)
File "C:\Users\melih.celik\Desktop\New_Backup\Yedek\Coding\Rand stuff\ssh_deneme(toplu).py", line 12, in config_backup
net_connect=ConnectHandler(**switch) #Baglanti kuruldu.
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko\ssh_dispatcher.py", line 312, in ConnectHandler
return ConnectionClass(*args, **kwargs)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko\base_connection.py", line 346, in init
self._open()
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko\base_connection.py", line 351, in _open
self.establish_connection()
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko\base_connection.py", line 920, in establish_connection
self.remote_conn_pre.connect(**ssh_connect_params)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\client.py", line 406, in connect
t.start_client(timeout=timeout)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\transport.py", line 660, in start_client
raise e
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\transport.py", line 2075, in run
self.kex_engine.parse_next(ptype, m)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\kex_gex.py", line 101, in parse_next
return self._parse_kexdh_gex_reply(m)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\kex_gex.py", line 281, in _parse_kexdh_gex_reply
self.transport._verify_key(host_key, sig)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\transport.py", line 1886, in _verify_key
if not key.verify_ssh_sig(self.H, Message(sig)):
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\dsskey.py", line 148, in verify_ssh_sig
key = dsa.DSAPublicNumbers(
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\cryptography\hazmat\primitives\asymmetric\dsa.py", line 212, in public_key
return backend.load_dsa_public_numbers(self)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 871, in load_dsa_public_numbers
dsa._check_dsa_parameters(numbers.parameter_numbers)
File "C:\Users\melih.celik\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko\tplink\tplink_jetstream.py", line 145, in _override_check_dsa_parameters
if crypto_utils.bit_length(parameters.q) not in [160, 256]:
AttributeError: module 'cryptography.utils' has no attribute 'bit_length'
Thanks for your help in advance.
It looks like tplink_jetstream.py assumes that a (now removed) helper function is available to it. The simplest fix here would be to go into that file and modify the line containing crypto_utils.bit_length(parameters.q) to read parameters.q.bit_length() instead.

ConnectionRefusedError when trying to connect to Gremlin Server using Python

I am trying to use gremlin with python with gremlinpython package. I am getting the following error. Can anyone tell me how to solve this ? Any help is appreciated.
Traceback (most recent call last):
File "C:/Users/Yash/IdeaProjects/new/gremlin.py", line 10, in <module>
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gremlin_python\driver\driver_remote_connection.py", line 45, in __init__
password=password)
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gremlin_python\driver\client.py", line 76, in __init__
self._fill_pool()
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gremlin_python\driver\client.py", line 88, in _fill_pool
conn = self._get_connection()
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gremlin_python\driver\client.py", line 101, in _get_connection
self._transport_factory, self._executor, self._pool)
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gremlin_python\driver\connection.py", line 40, in __init__
self.connect()
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gremlin_python\driver\connection.py", line 46, in connect
self._transport.connect(self._url)
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gremlin_python\driver\tornado\transport.py", line 33, in connect
lambda: websocket.websocket_connect(url))
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tornado\ioloop.py", line 458, in run_sync
return future_cell[0].result()
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
ConnectionRefusedError: [Errno 10061] Unknown error
check your configration,set the host as ip not hostname

ev3 closes connection when I attempt to connect through rpyc in python

I installed ev3dev on my ev3 brick so I could create programs on it with python. I am trying to use the "rpyc" library for python which can be found here. However, when I try to run this basic script which is given as an example on the link above:
import rpyc
conn = rpyc.classic.connect('192.168.137.3') # host name or IP address of the EV3
ev3 = conn.modules['ev3dev.ev3'] # import ev3dev.ev3 remotely
m = ev3.LargeMotor('outA')
m.run_timed(time_sp=1000, speed_sp=600)
I get multiple errors thrown at me through the terminal followed by the connection closing. I have followed all the instructions on the page and I also started the server script on the ev3 brick beforehand. When I run the above program the errors from python are displayed:
Traceback (most recent call last):
File "C:/Python27/cooode/moottertest.py", line 2, in <module>
conn = rpyc.classic.connect('192.168.137.3') # host name or IP address of the EV3
File "C:\Python27\lib\site-packages\rpyc\utils\classic.py", line 65, in connect
return factory.connect(host, port, SlaveService, ipv6 = ipv6)
File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 90, in connect
return connect_stream(s, service, config)
File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 51, in connect_stream
return connect_channel(Channel(stream), service = service, config = config)
File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 40, in connect_channel
return Connection(service, channel, config = config)
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 147, in __init__
self._init_service()
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 150, in _init_service
self._local_root.on_connect()
File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 145, in on_connect
self._conn.builtin = self._conn.modules.__builtin__
File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 114, in __getattr__
return self[name]
File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 111, in __getitem__
self.__cache[name] = self.__getmodule(name)
File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 196, in __call__
return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 71, in syncreq
return conn.sync_request(handler, oid, *args)
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 435, in sync_request
self.serve(0.1)
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 383, in serve
data = self._recv(timeout, wait_for_lock = True)
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 341, in _recv
data = self._channel.recv()
File "C:\Python27\lib\site-packages\rpyc\core\channel.py", line 50, in recv
header = self.stream.read(self.FRAME_HEADER.size)
File "C:\Python27\lib\site-packages\rpyc\core\stream.py", line 190, in read
raise EOFError("connection closed by peer")
EOFError: connection closed by peer
>>>
Then on my SSH session, here are the errors that are displayed:
robot#ev3dev:~$ ./rpyc_server.sh
INFO:SLAVE/18812:server started on [0.0.0.0]:18812
INFO:SLAVE/18812:accepted 192.168.137.1:5725
INFO:SLAVE/18812:welcome [192.168.137.1]:5725
INFO:SLAVE/18812:goodbye [192.168.137.1]:5725
ERROR:SLAVE/18812:client connection terminated abruptly
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 172, in _authenticate_and_serve_client
self._serve_client(sock2, credentials)
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 197, in _serve_client
conn._init_service()
File "/usr/lib/python3/dist-packages/rpyc/core/protocol.py", line 154, in _init_service
self._local_root.on_connect()
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 150, in on_connect
self._conn.builtin = self._conn.modules.builtins
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 121, in __getattr__
return self[name]
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 118, in __getitem__
self.__cache[name] = self.__getmodule(name)
TypeError: 'b'instancemethod'' object is not callable
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "/usr/lib/python3.4/threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 172, in _authenticate_and_serve_client
self._serve_client(sock2, credentials)
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 197, in _serve_client
conn._init_service()
File "/usr/lib/python3/dist-packages/rpyc/core/protocol.py", line 154, in _init_service
self._local_root.on_connect()
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 150, in on_connect
self._conn.builtin = self._conn.modules.builtins
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 121, in __getattr__
return self[name]
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 118, in __getitem__
self.__cache[name] = self.__getmodule(name)
TypeError: 'b'instancemethod'' object is not callable
What is going wrong here in these errors?
Are you connecting python2 and python3? ev3dev uses python2.
Use pyenv to install python3 and use it so that your python version of PC and ev3 are the same.
https://gist.github.com/jaydenkieran/75b2bbc32b5b70c4fdfb161ecdb6daa2
You might need to run this command first to install through curl:
sudo apt-get install curl

Categories

Resources