Open mh2019-av opened 4 years ago
the same problem, but removing .encode() didn't help.
works, if you add plaintext_login=True connection = routeros_api.RouterOsApiPool(IP, username='admin', password='password', plaintext_login=True)
Looks like this problem has something to do with the routeros version. In our network we have 24 different versions. The patch I included above is needed only for versions older than 6.43.1
Regardless, the code doesn't look right: the login and the password are encoded twice which is causing the error.
def login(self, login, password, plaintext_login):
response = None
if plaintext_login:
if isinstance(login, string_types):
login = login.encode()
if isinstance(password, string_types):
password = password.encode()
response = self.get_binary_resource('/').call('login',{ 'name': login, 'password': password })
else:
response = self.get_binary_resource('/').call('login')
if 'ret' in response.done_message:
token = binascii.unhexlify(response.done_message['ret'])
hasher = hashlib.md5()
hasher.update(b'\x00')
hasher.update(password.encode())
hasher.update(token)
hashed = b'00' + hasher.hexdigest().encode('ascii')
self.get_binary_resource('/').call(
'login', {'name': login.encode(), 'response': hashed})
Found this exception on some mikrotik devices. I fixed it by removing .encode() from lines: 94 and 98 in api.py.
Trace: