Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function net_connect.send_command, rstrip error #167

Closed
wmann opened this issue Jan 22, 2016 · 5 comments
Closed

Function net_connect.send_command, rstrip error #167

wmann opened this issue Jan 22, 2016 · 5 comments

Comments

@wmann
Copy link

wmann commented Jan 22, 2016

As the HP Procurve switches could run show commands in config mode. There was no problem using net_connect.send_config_set command for show commands. This works fine.

Code looks like this:
SSHClass = netmiko.ssh_dispatcher(device_type=switch['device_type'])
net_connect = SSHClass(**switch)
show_commands = ['show run']
output = net_connect.send_config_set(show_commands, delay_factor=2)

This works fine. Now I want to use the send_command function. I replaced send_config_set with send_command so the code looks like this

SSHClass = netmiko.ssh_dispatcher(device_type=switch['device_type'])
net_connect = SSHClass(**switch)
show_commands = ['show run']
output = net_connect.send_command(show_commands, delay_factor=2)

With this function I get the following error:

Traceback (most recent call last):
File "script.py", line 33, in
output = net_connect.send_command(show_commands, delay_factor=2)
File "C:\Python27\lib\site-packages\netmiko\base_connection.py", line 355, in send_command
command_string = command_string.rstrip("\n")
AttributeError: 'list' object has no attribute 'rstrip'

Any idea how to fix this?

Best Regards
wmann

@ktbyers
Copy link
Owner

ktbyers commented Jan 22, 2016

@wmann
show_commands needs to be a string and not a list.

So change this:
show_commands = ['show run']

To this:
show_commands = 'show run'

@wmann
Copy link
Author

wmann commented Jan 22, 2016

I should learn more python ;-(

@wmann
Copy link
Author

wmann commented Jan 22, 2016

But this
show_commands = ['show system', 'show interfaces transceiver']
seems to work. So if there is only one command only a string. When multiple then a list?

@wmann
Copy link
Author

wmann commented Jan 22, 2016

Damn, it might be to late for coding today.
Haven't changed the function in the second command. So how can I use a string and use multiple show commands?

@ktbyers
Copy link
Owner

ktbyers commented Jan 22, 2016

@wmann

Just use a for loop and gather the output.

show_commands = ['show system', 'show interfaces transceiver']
output = ''
for cmd in show_commands:
     output += net_connect.send_command(cmd, delay_factor=2)

Each time through the loop 'cmd' will be set to one of the commands.
output will have the results of the multiple commands

@ktbyers ktbyers closed this as completed Mar 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants