Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Love is in the offing. Be affectionate to one who adores you.


comp / comp.lang.python / Can't trap paramiko runtime trace-back error

SubjectAuthor
o Can't trap paramiko runtime trace-back errorVinode Singh Ujlain

1
Subject: Can't trap paramiko runtime trace-back error
From: Vinode Singh Ujlain
Newsgroups: comp.lang.python
Date: Wed, 22 May 2024 07:06 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ujlain@gmail.com (Vinode Singh Ujlain)
Newsgroups: comp.lang.python
Subject: Can't trap paramiko runtime trace-back error
Date: Wed, 22 May 2024 12:36:59 +0530
Lines: 70
Message-ID: <mailman.45.1716402365.2909.python-list@python.org>
References: <ffbbd7dd-5d43-4ca2-a178-d2491dfd19f4@gmail.com>
Reply-To: ujlain@gmail.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de x8M01nTmn4HEqNv0AzD2qggOnIo00f5t2uzRsfUvHMSg==
Cancel-Lock: sha1:Z90qpRAkbTU3167hbG1iGqd+Us8= sha256:JAbEUY6/I/unRki5gngSOEukFZBGQidThrkhAW4UGSQ=
Return-Path: <ujlain@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=UFOx9MC5;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.029
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'def': 0.04; 'traceback':
0.04; '(most': 0.05; 'error:': 0.05; 'last):': 0.05;
'subject:error': 0.07; 'import': 0.15; 'received:10.10': 0.16;
'runtime': 0.16; 'singh': 0.16; 'skip:" 60': 0.16; 'trap': 0.16;
'message-id:@gmail.com': 0.18; 'to:addr:python-list': 0.20;
'exception': 0.22; 'skip:_ 10': 0.22; 'code': 0.23; 'command':
0.23; 'skip:p 30': 0.23; 'run': 0.23; 'output': 0.28; 'error':
0.29; 'header:User-Agent:1': 0.30; 'raise': 0.31; 'credentials':
0.32; 'subject:Can': 0.32; 'server': 0.33; 'able': 0.34;
'received:google.com': 0.34; 'running': 0.34; 'handling': 0.35;
'close': 0.35; 'from:addr:gmail.com': 0.35; 'url-ip:13.107/16':
0.38; 'file': 0.38; 'block': 0.39; 'define': 0.40; 'connection':
0.61; 'above': 0.62; 'skip:o 20': 0.63; 'skip:b 10': 0.63; 'skip:t
20': 0.66; 'during': 0.69; 'skip:w 20': 0.69; 'below': 0.69;
'del': 0.70; 'reply-to:no real name:2**0': 0.78; 'header:Reply-
To:1': 0.79; 'client': 0.82; 'up,': 0.84; 'reply-
to:addr:gmail.com': 0.84; 'subject:back': 0.84; 'banner': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1716361628; x=1716966428; darn=python.org;
h=subject:from:to:content-language:reply-to:user-agent:mime-version
:date:message-id:from:to:cc:subject:date:message-id:reply-to;
bh=JzJDLCEsF21/EikRiyLZQQE0OBytCBEiZXY9lZaQoTk=;
b=UFOx9MC5FuNkmDXu1G7049/dB2i2XJXNu5sRiiPoKv/+DqIpXnG3NCpxqSfjyNUNU9
sd2frUDIXTsx27pkchoQt4je25DYaXv8D/Sir6k2S+Ew4zoE0CWYhTG3GP8kXx7n05VM
4vgHNk2zm4ypoi6d1ANRJMRMqP0LhPH06wD0v6X3Arh5OGJN19eP/1rEVqqCV3Gcvhk5
YWe0y1z2aAEP4P15m6nwhJfAjRPVpr4xbplLJVSr5xkDUUiYTFQ+zr5ZR3+nXNL7YHjl
ZZopj5hKHDygD6RfwN3m/pWQJYAycxk6acZ3HDcd0YCbA+hSBYnqa2wwIpOoo/nVKJvj
C76w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1716361628; x=1716966428;
h=subject:from:to:content-language:reply-to:user-agent:mime-version
:date:message-id:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to;
bh=JzJDLCEsF21/EikRiyLZQQE0OBytCBEiZXY9lZaQoTk=;
b=TSLU0LMJIqn++0v+491RN+LGxk27lQlbBHK8fw0tP+Iiai0i5PpTLhERVOMCctSliy
Ys6B7z83C+B3d2Ig69wCv84n/Z2osBLjK58rfLcUB6SX2umyQp052/O2WwGX/wWupV5T
x0+qAzvNJSckReEqMFX4jsQH+6iOT7nPxMVRhOJhcSVvpfHt+2/lBTv20kuUzVl+m3UY
BtyVTqKODUj98k0nnAtoMWmEiCF8wJZi6Y80OICP6bpg+IxkORBu2t2rEDWPaEL2Dito
T0sh8wk++BFIgb3S64QHq1TQ8J/PCyN8rdE2BKlCsmeET7Qxf5z2NWnfyeDRY9Qtgps9
PIIQ==
X-Gm-Message-State: AOJu0Yz5teIcJq69YiOXGxuL/xqst2u6x36ZS0zSdPmty1Regh6sYpWJ
Zco5kief3HJByGgGJQNoB/uQjL/SxvGa/JI4s2/KlEB0oGi5GNmeJbHiOQ==
X-Google-Smtp-Source: AGHT+IGndMTpiFF+yYCBYYeBCVvxYzXKvqL4ga8+zAAujBHy8ok9Q0daiXjX/w6QXXiTvmrUOha1hw==
X-Received: by 2002:a05:6a00:4fd0:b0:6e7:32a0:806a with SMTP id
d2e1a72fcca58-6f6d620f585mr1244434b3a.28.1716361627966;
Wed, 22 May 2024 00:07:07 -0700 (PDT)
User-Agent: Mozilla Thunderbird
Content-Language: en-US
X-Mailman-Approved-At: Wed, 22 May 2024 14:26:03 -0400
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <ffbbd7dd-5d43-4ca2-a178-d2491dfd19f4@gmail.com>
View all headers

When running the code below , I get error as enumerated below. Why am I
not able to trap this paramiko runtime traceback in try-except block ?

Exception (client): Error reading SSH protocol banner
Traceback (most recent call last):
  File
"/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py",
line 2327, in _check_banner
    buf = self.packetizer.readline(timeout)
  File
"/home/uzi/.local/lib/python3.8/site-packages/paramiko/packet.py", line
381, in readline
    buf += self._read_timeout(timeout)
  File
"/home/uzi/.local/lib/python3.8/site-packages/paramiko/packet.py", line
626, in _read_timeout
    raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File
"/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py",
line 2143, in run
    self._check_banner()
  File
"/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py",
line 2331, in _check_banner
    raise SSHException(
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner

SSH error: No existing session

importparamiko
importtime
defexecute():
try:
# Define the server and credentials
ip='p.q.r.s'
un, up, po='name', "passwd", 22
bto, sto=60, 60
ssh_client=paramiko.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip, port=po, username=un, password=up,
banner_timeout=bto, timeout=sto)
shell=ssh_client.invoke_shell()
defsend_command(command, wait_time=1):
shell.send(command+'\n')
time.sleep(wait_time) # Give the command some time to execute
whilenotshell.recv_ready():
time.sleep(0.1)
returnshell.recv(8192).decode()
output=send_command('date')
print("Output:\n", output)
delssh_client
exceptparamiko.SSHExceptionase:
print(f"SSH error: {e}")
exceptExceptionase:
print(f"Error: {e}")
finally:
# Close the SSH client connection
delssh_client
execute()

--
Warm Regards,
Vinode Singh Ujlain | https://www.linkedin.com/in/ujlain/
------------------------------------------------------------------------

1

rocksolid light 0.9.8
clearnet tor