luqasz/librouteros

Unicode in DHCP comments

Closed this issue · 2 comments

I am using Home Assistant, When I start the integration I get an error. I understand this is a problem from having Unicode/utf8 in DHCP comments.

Logger: homeassistant.config_entries
Source: components/mikrotik/hub.py:259
First occurred: 15:17:45 (1 occurrences)
Last logged: 15:17:45

Error setting up entry Mikrotik for mikrotik
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 304, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/usr/src/homeassistant/homeassistant/components/mikrotik/init.py", line 73, in async_setup_entry
if not await hub.async_setup():
File "/usr/src/homeassistant/homeassistant/components/mikrotik/hub.py", line 387, in async_setup
await self.hass.async_add_executor_job(self._mk_data.update)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/mikrotik/hub.py", line 283, in update
self.update_devices()
File "/usr/src/homeassistant/homeassistant/components/mikrotik/hub.py", line 178, in update_devices
self.all_devices = self.get_list_from_interface(DHCP)
File "/usr/src/homeassistant/homeassistant/components/mikrotik/hub.py", line 165, in get_list_from_interface
result = self.command(MIKROTIK_SERVICES[interface])
File "/usr/src/homeassistant/homeassistant/components/mikrotik/hub.py", line 259, in command
response = list(self.api(cmd=cmd))
File "/usr/local/lib/python3.9/site-packages/librouteros/api.py", line 28, in call
yield from self.readResponse()
File "/usr/local/lib/python3.9/site-packages/librouteros/api.py", line 60, in readResponse
reply_word, words = self.readSentence()
File "/usr/local/lib/python3.9/site-packages/librouteros/api.py", line 46, in readSentence
reply_word, words = self.protocol.readSentence()
File "/usr/local/lib/python3.9/site-packages/librouteros/protocol.py", line 189, in readSentence
sentence = tuple(word for word in iter(self.readWord, ''))
File "/usr/local/lib/python3.9/site-packages/librouteros/protocol.py", line 189, in
sentence = tuple(word for word in iter(self.readWord, ''))
File "/usr/local/lib/python3.9/site-packages/librouteros/protocol.py", line 206, in readWord
return word.decode(encoding=self.encoding, errors='strict')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 18: invalid continuation byte

I've changed behavior when decoding characters to ignore. Released in https://github.com/luqasz/librouteros/tree/3.2.0

Thanks, I hope it will soon be included in the Home Assistant.