socialwifi / RouterOS-api

Python API to RouterBoard devices produced by MikroTik.
MIT License
251 stars 100 forks source link

Ignore errors on StringField value. #58

Open Nekmo opened 4 years ago

Nekmo commented 4 years ago

Added errors='ignore' to StringField (avoid a exception due to encoding issues) and added environ variable for change the encoding to be used when connecting to the router.

eduardomazolini commented 3 years ago

I had the same problem with a dhcp hostname, a single windows machine broke the entire solution. At the very least the use of ignore error should be implemented. I use:

def get_python_value(self, bytes):
    for d in ['utf-8','latin1']:
        try:
            return bytes.decode(d)
        except:
            pass
    return bytes.decode(encoding='utf-8', errors='ignore')