this and the next one can be simplified as:

    except (KeyError, AttributeError):
        return os_version

Because you are having the same behavior on both exceptions