dell / libsmbios

library for interacting with Dell SMBIOS tables
Other
192 stars 39 forks source link

Running smbios-keyboard-ctl gives UnicodeDecodeError in _common.py #41

Closed katonagl closed 6 years ago

katonagl commented 6 years ago

I have tried to run smbios-keyboard-ctl -vi, but I encountered the following error:

Libsmbios version : 2.3.3
smbios-keyboard-ctl version : 2.3.3

 Capabilities of KeyBoard Illumination on your system: 
-------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/sbin/smbios-keyboard-ctl", line 655, in main
    PrintKeyBoardCapab()
  File "/usr/sbin/smbios-keyboard-ctl", line 455, in PrintKeyBoardCapab
    res = smi.simple_ci_smi( 4, 11, 0 )
  File "/usr/lib/python3.6/site-packages/libsmbios_c/trace_decorator.py", line 103, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/libsmbios_c/smi.py", line 145, in simple_ci_smi
    DLL.dell_simple_ci_smi(smiClass, select, arg, res)
  File "/usr/lib/python3.6/site-packages/libsmbios_c/trace_decorator.py", line 103, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/libsmbios_c/_common.py", line 65, in _errorOnNegativeFN
    _doExc(exception_fn, result, func, args, _("function returned negative error code") )
  File "/usr/lib/python3.6/site-packages/libsmbios_c/_common.py", line 25, in _doExc
    raise exception_fn(r, f, a)
  File "/usr/lib/python3.6/site-packages/libsmbios_c/smi.py", line 140, in <lambda>
    DLL.dell_simple_ci_smi.errcheck = errorOnNegativeFN(lambda r,f,a: SMIExecutionError(_strerror()))
  File "/usr/lib/python3.6/site-packages/libsmbios_c/trace_decorator.py", line 103, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/libsmbios_c/smi.py", line 135, in _strerror
    return DLL.dell_smi_strerror()
  File "_ctypes/callproc.c", line 918, in GetResult
  File "/usr/lib/python3.6/site-packages/libsmbios_c/_common.py", line 73, in _check_retval_
    return value.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/sbin/smbios-keyboard-ctl", line 709, in <module>
    sys.exit( main() )
  File "/usr/sbin/smbios-keyboard-ctl", line 692, in main
    except (smbios.TableParseError, token.TokenTableParseError) as e:
NameError: name 'token' is not defined
superm1 commented 6 years ago

Are you sure you're using 2.3.3? Please confirm if this issue still happens in 2.4.0.

katonagl commented 6 years ago

Yes, it is 2.3.3. I'm using Opensuse Tumbleweed, thought it has the latest version. Sorry for that.

Now I have removed the version installed from repo, cloned from git, followed install instructions and now I have

Traceback (most recent call last):
  File "/usr/local/sbin/smbios-keyboard-ctl", line 33, in <module>
    import cli
  File "/usr/local/share/smbios-utils/cli.py", line 7, in <module>
    from libsmbios_c import memory, smi, cmos, pkgconfdir, localedir, GETTEXT_PACKAGE
ImportError: bad magic number in 'libsmbios_c': b'\x03\xf3\r\n'
superm1 commented 6 years ago

What version of python are you using? That looks strikingly like trying to use python 2 instead of 3.

superm1 commented 6 years ago

Or are you using a non english locale? Can you share your locale details?

katonagl commented 6 years ago

Actually I have both python 2 and 3 installed, but /usr/bin/python3 is explicitly stated in the files and python3 is indeed python 3.6.4

superm1 commented 6 years ago

OK, so maybe locale related issue? What's your locale?

katonagl commented 6 years ago

My locale is Hungarian, hu_HU.UTF-8

katonagl commented 6 years ago

changing to en_US.UTF-8 does not help

superm1 commented 6 years ago

Can you try to narrow down which of the imports if causing the problem for you?

katonagl commented 6 years ago

Definitely, although I would need some hint on what to do.

superm1 commented 6 years ago

From a python terminal:

from libsmbios_c import memory
from libsmbios_c import smi
from libsmbios_c import cmos

Etc to cover each of those and see which fails.

katonagl commented 6 years ago

All of these resulted in


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: bad magic number in 'libsmbios_c': b'\x03\xf3\r\n'

I guess this is not much help.

superm1 commented 6 years ago

Looking over a similar complaint https://github.com/Miserlou/Zappa/issues/854 there are old pyc files sitting around. Can you look around and remove them?

katonagl commented 6 years ago

OK, here what I have done.

I have run find . -name \*.pyc -delete and git clean -fdx in git cone directory

Then ./autogen.sh, make, make install

Nothing changed. Have I interpreted the linked issue correctly?

superm1 commented 6 years ago

The pyc files are probably on your filesystem under /usr/local/ or /usr/

katonagl commented 6 years ago

OK, I have removed pyc files. Now the result is:

Libsmbios version : 2.4.1
smbios-keyboard-ctl version : 2.4.1

 Capabilities of KeyBoard Illumination on your system: 
-------------------------------------------------------------------
ERROR: Could not execute SMI.
The smi library returned this error:
b'\xc0}\xf2K\xf9U'

Common problems are:

    -- 'SMM Mitigations' is enabled in BIOS setup.
        Run kernel 4.15 or later with 
        dell-smbios-wmi enabled.
         or 
        Disable 'SMM mitigations' in BIOS setup.

    -- Insufficient permissions to perform operation.
       Try running as a more privileged account.
          Linux  : run as 'root' user
          Windows: run as 'administrator' user

    -- dell-smbios-wmi driver not loaded 
       Try loading the dell-smbios-wmi driver 
          Linux : modprobe dell-smbios-wmi 

    -- Call filtered by Linux kernel 
       Some functionality is natively supported 
       by the Linux kernel 

    -- dcdbas device driver not loaded.
       Try loading the dcdbas driver
          Linux  : modprobe dcdbas
katonagl commented 6 years ago

Running as root, modprobes done

superm1 commented 6 years ago

What hardware? Do you have SMM mitigations turned on in BIOS setup? Is this kernel 4.15 or later?

katonagl commented 6 years ago

Dell E7470, Kernel 4.15.7. I do not know what SMM mitigation mean in the bios

superm1 commented 6 years ago

Ah, so kernel 4.15. This is probably what's going on.

    -- Call filtered by Linux kernel 
       Some functionality is natively supported 
       by the Linux kernel 

If you check in your system log you'll probably see a message about the call being filtered from the kernel. Starting with 4.15 the kernel locks out userspace from accessing some of these requests. Use the dell-laptop kernel interface for changing it instead.

katonagl commented 6 years ago

OK. I see. I will check that. Thanks

katonagl commented 6 years ago

dmesg says:

dell-smbios A80593CE-A997-11DA-B012-B622A1EF5492: Invalid call 4/11: 0

superm1 commented 6 years ago

Yep, so that is kernel filtering. You'll want to use this instead. https://github.com/torvalds/linux/blob/master/Documentation/ABI/testing/sysfs-platform-dell-laptop