raffzwo
raffzwo

Reputation: 53

Python Netmiko OSError: Search pattern never detected in send_command_expect:

I recently started programming with Python. I work as a network engineer and am currently building a program to pull "state dumps" from Ciena devices. I use netmiko to connect to the device. Now I always get the following error:

OSError: Search pattern never detected in send_command_expect: 5160_1>

"5160_1>" is the hostname / prompt on the switch. I have read that I can give "expect_string" to a "send_command". Unfortunately, this has no effect and I still get this error.

This is the function with which I create the state dump and call the function for the file download.

def create_sd():
    for ip in sw_connect_ips:
        try:
            sw_connection = ConnectHandler(device_type=sw_dev_type, host=ip, username=sw_usr, password=sw_pw)
            try:
                print('\nconnnected to host > ' + ip + '\n')
                hostname = sw_connection.find_prompt()
                print('hostname of device > ' + hostname)
                sw_connection.send_command('system server sftp enable', expect_string=hostname)
                sw_connection.send_command('configuration save', expect_string=hostname)
                sw_output = sw_connection.send_command('system state-dump file-name ' + ip + '_sd_timestamp_' + str(date.hour) + '_' + str(date.minute) + '_' + str(date.second), expect_string=hostname + ' ')
                filename = ip + '_sd_timestamp_' + str(date.hour) + '_' + str(date.minute) + '_' + str(date.second)
                print('got state-dump ' + filename + ' from host > ' + ip)
                logging.debug(sw_output)
                logging.debug(sw_connection)
                sw_connection.disconnect()
                try:
                    sftp_get(filename, ip)
                except:
                    raise Exception('scp failed')
            except:
                raise Exception('command does not exist on switch > ' + ip)
        except:
            raise SSHException('unable to connect to switch check username, password and ip address')

I don't know whether all exceptions make so much sense. Maybe someone has a tip for me.

Thanks in advance.

Edit: What is strange in my opinion is that it only occurs with some switches.

Upvotes: 1

Views: 5712

Answers (1)

raffzwo
raffzwo

Reputation: 53

in the command with which the state dump is created, I have increased the "send_command" delay factor to 5.

sw_output = sw_connection.send_command ('system state-dump file-name' + ip + '_sd_timestamp_' + str (date.hour) + '_' + str (date.minute) + '_' + str (date.second) , expect_string = hostname, delay_factor = 5)

As a result, I no longer get a netmiko exception and the program runs without problems.

Upvotes: 1

Related Questions