question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TP-Link switch T1500G - Unable to find prompt

See original GitHub issue

I’m attempting to use Netmiko with a TP-link T1500G. There’s no driver for this at present, however from what I’ve read the CLI is similar to Cisco, and if I can get my head round this I’m happy to create one.

Using the code below I can connect, login and see the prompt in the debug:

from netmiko import ConnectHandler
from cryptography.hazmat.primitives.asymmetric import dsa
from cryptography import utils as crypto_utils
import logging

def _override_check_dsa_parameters(parameters):
    """Override check_dsa_parameters from cryptography's dsa.py

    Without this the error below occurs:
    ValueError: p must be exactly 1024, 2048, or 3072 bits long

    Allows for shorter or longer parameters.p to be returned from the server's host key. This is a
    HORRIBLE hack and a security risk, please remove if possible!
    """
    if crypto_utils.bit_length(parameters.q) not in [160, 256]:
        raise ValueError("q must be exactly 160 or 256 bits long")

    if not (1 < parameters.g < parameters.p):
        raise ValueError("g, p don't satisfy 1 < g < p.")

dsa._check_dsa_parameters = _override_check_dsa_parameters

logging.basicConfig(filename="network_script.log", level=logging.DEBUG)
logger = logging.getLogger("Netmiko")

device = {
    "device_type": "cisco_ios",
    "ip": "192.168.178.99",
    "username": "davmin",
    "password": "u65mzO6w9ydr2",
    "global_delay_factor": 1,
    "port": 22,
    "timeout": 120,
    "use_keys": False,
    "key_file": "/Users/daveuser/.ssh/id_rsa.pub",
    "secret": "u65mzO6w9ydr2",
    "passphrase": "u65mzO6w9ydr2",
}


net_connect = ConnectHandler(**device)

However this results in an "ValueError: Unable to find prompt: " error.

The log looks like this:

DEBUG:paramiko.transport:starting thread (client mode): 0x2708320 DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.4.2 DEBUG:paramiko.transport:Remote version/idstring: SSH-1.99-IPSSH-6.6.0 INFO:paramiko.transport:Connected (version 1.99, client IPSSH-6.6.0) DEBUG:paramiko.transport:kex algos:[‘diffie-hellman-group1-sha1’] server key:[‘ssh-dss’] client encrypt:[‘aes128-cbc’, ‘aes192-cbc’, ‘aes256-cbc’, ‘blowfish-cbc’, ‘cast128-cbc’, ‘3des-cbc’] server encrypt:[‘aes128-cbc’, ‘aes192-cbc’, ‘aes256-cbc’, ‘blowfish-cbc’, ‘cast128-cbc’, ‘3des-cbc’] client mac:[‘hmac-sha1’, ‘hmac-sha1-96’, ‘hmac-md5’, ‘hmac-md5-96’] server mac:[‘hmac-sha1’, ‘hmac-sha1-96’, ‘hmac-md5’, ‘hmac-md5-96’] client compress:[‘none’] server compress:[‘none’] client lang:[‘’] server lang:[‘’] kex follows?False DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1 DEBUG:paramiko.transport:HostKey agreed: ssh-dss DEBUG:paramiko.transport:Cipher agreed: aes128-cbc DEBUG:paramiko.transport:MAC agreed: hmac-sha1 DEBUG:paramiko.transport:Compression agreed: none DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo <built-in function openssl_sha1> DEBUG:paramiko.transport:Switch to new keys … DEBUG:paramiko.transport:Adding ssh-dss host key for 192.168.178.99: b’6e3ca110ab027f73d8aa7e40d0516ef8’ DEBUG:paramiko.transport:userauth is OK INFO:paramiko.transport:Authentication (password) successful! DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes DEBUG:paramiko.transport:Secsh channel 0 opened. DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:netmiko:read_channel:

T1500G-10PS> DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:Pattern is: # DEBUG:netmiko:write_channel: b’exit\n’

This is how I manually connect and submit commands from the terminal

OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 51: Applying options for 192.168.178.99
debug1: Connecting to 192.168.178.99 [192.168.178.99] port 22.
debug1: Connection established.
debug1: identity file id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 1.99, remote software version IPSSH-6.6.0
debug1: no match: IPSSH-6.6.0
debug1: Authenticating to 192.168.178.99:22 as 'admin'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group1-sha1
debug1: kex: host key algorithm: ssh-dss
debug1: kex: server->client cipher: aes128-cbc MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-cbc MAC: hmac-sha1 compression: none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: ssh-dss SHA256:h1gD8T017XJ19NjY3wD9Vob81jHYUJubf2M23KLU7OU
debug1: Host '[192.168.178.99]:22' is known and matches the DSA host key.
debug1: Found key in /Users/daveuser/.ssh/known_hosts:8
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
Authenticated with partial success.
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
admin@192.168.178.99's password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.178.99 ([192.168.178.99]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network

T1500G-10PS>enable

T1500G-10PS#configure

T1500G-10PS(config)#interface gigabitEthernet 1/0/2

T1500G-10PS(config-if)#switchport pvid 2

T1500G-10PS(config-if)#

As I follow the session_preparation using the debugger, I can see that _test_channel_read succeeds, reading ‘\r\n\rT1500G-10PS>’ from the channel, and matching it to the ‘[>#]’ pattern, however set_base_prompt does not. It seems that read_channel in find_prompt returns an empty string, and I’m not sure why.

As shown in paste from the terminal above, there’s a newline between every “T1500G-10PS>” prompt, could this be the cause of this issue?

Any pointers much appreciated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lifeofdavecommented, Jun 20, 2019

However, if I replace this line self.write_channel(self.RETURN) (https://github.com/ktbyers/netmiko/blob/develop/netmiko/base_connection.py#L925) with self.write_channel("\r\n")

The print statement outputs this

‘\r\n\r\n\rT1500G-10PS>’

Before resulting in this traceback

Traceback (most recent call last):
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/paramiko/channel.py", line 699, in recv
    out = self.in_buffer.read(nbytes, self.timeout)
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/paramiko/buffered_pipe.py", line 164, in read
    raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/netmiko/base_connection.py", line 519, in _read_channel_expect
    new_data = self.remote_conn.recv(MAX_BUFFER)
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/paramiko/channel.py", line 701, in recv
    raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/davidsinclair/projects/netzoom_platform/tests/netmiko_test1.py", line 43, in <module>
    net_connect = ConnectHandler(**device)
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/netmiko/ssh_dispatcher.py", line 228, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/netmiko/base_connection.py", line 313, in __init__
    self._try_session_preparation()
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/netmiko/base_connection.py", line 723, in _try_session_preparation
    self.session_preparation()
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/netmiko/cisco/cisco_ios.py", line 19, in session_preparation
    self.disable_paging()
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/netmiko/base_connection.py", line 989, in disable_paging
    output = self.read_until_prompt()
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/netmiko/base_connection.py", line 590, in read_until_prompt
    return self._read_channel_expect(*args, **kwargs)
  File "/Users/davidsinclair/virtualenvs/netzoom_3_6_7/lib/python3.6/site-packages/netmiko/base_connection.py", line 528, in _read_channel_expect
    "Timed-out reading channel, data not available."
netmiko.ssh_exception.NetMikoTimeoutException: Timed-out reading channel, data not available.

Feels like progress 😃

0reactions
carlmontanaricommented, Jun 21, 2019

@lifeofdave sent you a note and link to a branch on my netmiko fork. If you want to take that and run w/ it (on your own or create a driver for it), have at it! I think we’ll close this at this point though as this seems like a one off TP Link quirk. Let us know if you run into any other issues!

Read more comments on GitHub >

github_iconTop Results From Across the Web

accessing-the-switch - TP-Link
1)Make sure the switch and the PC are in the same LAN (Local Area Network). Click Start and type in cmd in the...
Read more >
Accessing the Switch Securely - TP-Link
There are two methods to access the switch securely, that is via SSH and via HTTPS. ... Otherwise, the TFTP server cannot find...
Read more >
What should I do if I cannot access the web management ...
First of all, check the model of your switch to verify it is web-manageable. Until now, only TP-Link Easy Smart/Unmanaged Pro/Smart/Managed ...
Read more >
T1500G-10PS(UN)_V1_User Guide - TP-Link
If the DC input fails, the PoE input on the PD port will supply power to the switch instead. ▫ T1500G-10PS. The rear...
Read more >
Troubleshooting Instruction of TP-Link switch's SFP port
Sometimes, we will encounter the compatible problem that the TP-link smart/managed switches cannot link up with other brands switch when ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found