ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.63k stars 1.31k forks source link

err :output = net_connect.send_command_timing('show running-config') #3426

Open hahae2 opened 7 months ago

hahae2 commented 7 months ago

Description of Issue/Question

import netmiko
import logging
logging.basicConfig(level=logging.DEBUG)

device = {
    'device_type': 'cisco_ios',
    'ip': '192.168.100.5',
    'username': 'aaa',  
    'password': '123456a', 
    #'port': "23",
    'secret': 123',
    'global_delay_factor': 2,
}

net_connect = netmiko.ConnectHandler(**device)   
net_connect.enable()   
in_enable_mode = net_connect.check_enable_mode()
if in_enable_mode:
    print("Successfully entered enable mode***********************************")
else:
    print("Failed to enter enable mode ")    

output = net_connect.send_command_timing('show running-config')          

print(output)
net_connect.disconnect()    

debugu : DEBUG:paramiko.transport:starting thread (client mode): 0x317bd370 DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_3.4.0 DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-Cisco-1.25 INFO:paramiko.transport:Connected (version 2.0, client Cisco-1.25) DEBUG:paramiko.transport:=== Key exchange possibilities === DEBUG:paramiko.transport:kex algos: diffie-hellman-group1-sha1 DEBUG:paramiko.transport:server key: ssh-rsa DEBUG:paramiko.transport:client encrypt: aes128-cbc, 3des-cbc, aes192-cbc, aes256-cbc DEBUG:paramiko.transport:server encrypt: aes128-cbc, 3des-cbc, aes192-cbc, aes256-cbc DEBUG:paramiko.transport:client mac: hmac-sha1, hmac-sha1-96, hmac-md5, hmac-md5-96 DEBUG:paramiko.transport:server mac: hmac-sha1, hmac-sha1-96, hmac-md5, hmac-md5-96 DEBUG:paramiko.transport:client compress: none DEBUG:paramiko.transport:server compress: none DEBUG:paramiko.transport:client lang: DEBUG:paramiko.transport:server lang: DEBUG:paramiko.transport:kex follows: False DEBUG:paramiko.transport:=== Key exchange agreements === DEBUG:paramiko.transport:Kex: diffie-hellman-group1-sha1 DEBUG:paramiko.transport:HostKey: ssh-rsa DEBUG:paramiko.transport:Cipher: aes128-cbc DEBUG:paramiko.transport:MAC: hmac-sha1 DEBUG:paramiko.transport:Compression: none DEBUG:paramiko.transport:=== End of kex handshake === DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo DEBUG:paramiko.transport:Switch to new keys ... DEBUG:paramiko.transport:Adding ssh-rsa host key for 192.168.100.5: b'b2cb52802ddd4e20a8098e67d216beea' 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: 4096 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:write_channel: b'\n' DEBUG:netmiko:write_channel: b'terminal width 511\n' DEBUG:netmiko:read_channel: cisco123# cisco123# DEBUG:netmiko:read_channel: terminal width 511 cisco123# DEBUG:netmiko:Pattern found: (terminal width 511) cisco123# cisco123#terminal width 511 DEBUG:netmiko:In disable_paging DEBUG:netmiko:Command: terminal length 0

DEBUG:netmiko:write_channel: b'terminal length 0\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: terminal length 0 cisco123# DEBUG:netmiko:Pattern found: (terminal\ length\ 0) cisco123##terminal length 0 DEBUG:netmiko: cisco123##terminal length 0 DEBUG:netmiko:Exiting disable_paging DEBUG:netmiko:read_channel: DEBUG:netmiko:Clear buffer detects data in the channel DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: cisco123# DEBUG:netmiko: Parenthesis found in pattern.

pattern: (#|>)

This can be problemtic when used in read_until_pattern().

You should ensure that you use either non-capture groups i.e. '(?:' or that the
parenthesis completely wrap the pattern '(pattern)' DEBUG:netmiko:Pattern found: (#|>) cisco123# DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is cisco123# DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: cisco123#

cisco123# DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: cisco123# DEBUG:netmiko:Pattern found: (BDEL-C10012-R1-A.*) cisco123# Successfully entered enable mode*** show tech DEBUG:netmiko:write_channel: b'show running-config\n' #####################ERR DEBUG:netmiko:read_channel: show running-config ^ % Invalid input detected at '^' marker.

cisco123# DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: ^ % Invalid input detected at '^' marker.

DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: cisco123# DEBUG:netmiko:Pattern found: ([>#]) cisco123# DEBUG:netmiko:write_channel: b'exit\n' DEBUG:paramiko.transport:EOF in transport thread

Note: Please check https://guides.github.com/features/mastering-markdown/ to see how to properly format your request.

Setup

Netmiko version

(Paste verbatim output from pip freeze | grep netmiko between quotes below)

Netmiko device_type (if relevant to the issue)

(Paste device_type between quotes below)

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

Relevant Python code

(Please try to essentialize your Python code to the minimum code needed to reproduce the issue) (Paste the code between the quotes below)

ktbyers commented 7 months ago

It looks like you don't have permissions to access the running-config.

DEBUG:netmiko:write_channel: b'show running-config\n' #####################ERR
DEBUG:netmiko:read_channel: show running-config
^
% Invalid input detected at '^' marker.

cisco123#

That error is from the device itself.