Closed wpureza closed 3 years ago
Can you try this fix here:
Hi, Kirk. Thank you for your reply. I tried the fix, but im not getting the output from var "a_string". Follow my code:
from netmiko import ConnectHandler
def login(ip, user, password):
device = {
'device_type': 'mikrotik_routeros',
'host': ip,
'username': user,
'password': password,
'port': 22
}
conn = ConnectHandler(**device)
return conn
if __name__ == '__main__':
ip = '192.168.88.1'
user = 'admin'
password = 'pass'
connection = login(ip, user, password)
print(connection.find_prompt())
cmd = connection.send_command('/interface bridge host print')
print(cmd)
Output:
C:\Users\Administrator\PycharmProjects\netmiko_test\venv\Scripts\python.exe C:/Users/Administrator/PycharmProjects/netmiko_test/teste.py
[admin@MikroTik] >
Process finished with exit code 0
Can you turn on Netmiko logging so we can get some more details about what is occurring?
Hi, Kirk. Sorry for the delay.
Follow the log file for the same code posted before: netmiko_mikrotik_10032020.log
@wpureza So is the issue you don't get output--correct?
@ktbyers
Hi , I have same problem . I tried to use netmiko sample , and got an error I resolved the error with your previous message , I fix it but there is no result of my command .
this is my code :
`#!/usr/bin/env python from netmiko import Netmiko from getpass import getpass
dev = { "host": "x.x.x.x", "username": "username", "password": "password", "device_type": "mikrotik_routeros", }
net_connect = Netmiko(**dev) command = "/ip add pr"
print() print(net_connect.find_prompt()) output = net_connect.send_command(command) net_connect.disconnect() print(output) print()`
and the result :
`PS C:\Users\Mehrzad> & C:/Users/Mehrzad/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Mehrzad/Desktop/mik.py
[admin@Mehr_Home] >
PS C:\Users\Mehrzad> `
I'm on the same page here. If I try the suggested fix #1606 I don't get the output.
@mehrzadmo
If you do this manually via SSH on the CLI:
command = "/ip add pr"
Can you show me what the SSH session looks like i.e. what it looks like manually?
@ktbyers thanks for your attention , there is the result
[admin@Mehr_Home] > /ip add pr
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 192.168.10.1/24 192.168.10.0 ether1
1 D a.b.c.d/32 x.y.z.a pppoe-out1
2 D 192.168.121.254/24 192.168.121.0 eoip-VPN
[admin@Mehr_Home] >
@mehrzadmo And your code works with Netmiko 2.4.2?
@ktbyers I tried ! thats worked !
[admin@Mehr_Home] >
[admin@Mehr_Home] >
PS C:\Users\Mehrzad> & C:/Users/Mehrzad/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Mehrzad/Desktop/mik.py
[admin@Mehr_Home] >
[admin@Mehr_Home] >
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 192.168.10.1/24 192.168.10.0 ether1
1 D x.x.x.x/32 x.x.x.x pppoe-out1
2 D 192.168.121.254/24 192.168.121.0 eoip-VPN
The same issue is happening for me as described by @shahro0z . The described fix provides no output. I will add logs soon.
@MajesticFalcon So just to verify...using Netmiko 3.1.0 when you execute:
/system routerboard print
using send_command()
you receive no output back. Is that correct?
When I run the command at the terminal from putty, I get a response. When using netmiko 3.0, I get the index error. When applying the fix up above, I get blank output.
Hmmm, and what happens if you use Netmiko 3.1.0 and you set global_cmd_verify=False
? This is an argument to ConnectHandler.
That works. I believe there are two existing issues.
After more testing, it appears the space in the hostname is not the issue. Replacing spaces with other characters doesnt fix it. I believe it may have to do with firmware. I will update tonight and report back.
@MajesticFalcon What did you find out here?
Set global_cmd_verify=False
does not solve the issue. Mikrotik returns for each command doble echo command with prompt \r{comand}\n{echo_promp}{comand}\n{comand_result}{next_prompt}
if cmd_verify
is enabled only remove first comand and read loop (https://github.com/ktbyers/netmiko/blob/063bdd4184bbb08fad5f82f2b429ab1323155fc3/netmiko/base_connection.py#L1405) read until echo_prompt and skip command result.
a posible solution https://github.com/johnbarneta/netmiko/commit/d408eb532cbd2b5ee407ff1fa854978784886571 tested on various devices and it works fine!
@johnbarneta it works, but your next commit https://github.com/johnbarneta/netmiko/commit/439dc5159f5b56a7c0c2cc61712367d0f918ab88 is also needed to completely fix the issue
Ran into this too :s
On netmiko 3.1.1 the 'global_cmd_verify':False
is (still) required to get commands working
Ran into this too :s On netmiko 3.1.1 the
'global_cmd_verify':False
is (still) required to get commands working
When 'global_cmd_verify':False
is set, https://github.com/ktbyers/netmiko/commit/944953c896e96d76ecac1cf25991f3a0e148c9b0 and https://github.com/johnbarneta/netmiko/commit/d408eb532cbd2b5ee407ff1fa854978784886571 gives a partial result
Ran into this too :s On netmiko 3.1.1 the
'global_cmd_verify':False
is (still) required to get commands workingWhen
'global_cmd_verify':False
is set, 944953c and johnbarneta@d408eb5 gives a partial result
This worked for me
Anyone have a Microtik device I can test against so I can see if I can get a more permanent fix in place?
Anyone have a Microtik device I can test against so I can see if I can get a more permanent fix in place?
You can also grab a Cloud Hosted Router and setup a virtual one.
Anyone have a Microtik device I can test against so I can see if I can get a more permanent fix in place?
Sure. Ping me.
Hmmm, and what happens if you use Netmiko 3.1.0 and you set
global_cmd_verify=False
? This is an argument to ConnectHandler.
Yes, this working :)
I was able to get send_command()
to a Mikrotik working. I started with the "v3.4.0" tag from this repo (the most recent released version as of my writing), then applied the patches jgmel/netmiko@d408eb532cbd2b5ee407ff1fa854978784886571 and jgmel/netmiko@439dc5159f5b56a7c0c2cc61712367d0f918ab88 in that order. After re-installing this patched version, everything seemed to work, even without using global_cmd_verify=False
.
The prompt string is not stripped from the output, however.
Proposed fix for the Mikrotik issues:
https://github.com/ktbyers/netmiko/pull/2362
If anyone is willing to test this, it would be very much appreciated.
Anyone have a Microtik device I can test against so I can see if I can get a more permanent fix in place?
Apart from the VM there is also an online demo (read only user account) that you can ssh to. hostname: demo.mt.lv OR hostname: demo2.mt.lv username: demo no password. More details here: https://mikrotik.com/software demo2.mt.lv is currently running beta software so demo.mt.lv would be a better test target.
Should be fixed in this PR:
Hi,
after upgrade the netmiko module from 2.4.2 to 3.0.0 the "send_command" function, for mikrotik RouterOS device, is not working. The traceback message is showing "IndexError" exception for the list "response_list[-2]" in mikrotik_ssh module.
Follow:
The "find_prompt" function is working. I'm using Python 3.7.
Regards, Walter