Fix python crash if python 3.8 "distro" module is missing

Bug #1867636 reported by Martin Wilck
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
HPLIP
New
Undecided
Unassigned

Bug Description

hp-toolbox crashes with python 3.8 is used and the python "distro" module is unavailable.

$ hp-toolbox

HP Linux Imaging and Printing System (ver. 3.19.12)
HP Device Manager ver. 15.0

Copyright (c) 2001-18 HP Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

Traceback (most recent call last):
  File "/usr/share/hplip/base/password.py", line 85, in get_distro_name
    os_name = platform.dist()[0]
AttributeError: module 'platform' has no attribute 'dist'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/hp-toolbox", line 280, in <module>
    toolbox = ui.DevMgr5(__version__, device_uri, None)
  File "/usr/share/hplip/ui5/devmgr5.py", line 235, in __init__
    core = CoreInstall(MODE_CHECK)
  File "/usr/share/hplip/installer/core_install.py", line 240, in __init__
    self.passwordObj = password.Password(ui_mode)
  File "/usr/share/hplip/base/password.py", line 118, in __init__
    self.__readAuthType() # self.__authType
  File "/usr/share/hplip/base/password.py", line 140, in __readAuthType
    distro_name = get_distro_name().lower()
  File "/usr/share/hplip/base/password.py", line 87, in get_distro_name
    import distro
ModuleNotFoundError: No module named 'distro'

This crash can be easily avoided by catching the respective Exception. Both password.py and core_install.py contain existing code to determine the distro via "lsb_release" if the python mechanism fails.

Revision history for this message
Martin Wilck (mwilck) wrote :
Revision history for this message
Felipe Casado (vivamudhoney) wrote :

This happens to me too still with version 3.20.11 in ubuntu 20.04. The command hp-plugin crashes too. The patch does not help me, but reading the previous comment I removed completely the distro sections and then it works by using the fallback mecanism. I attach the patch. To use it:
hplip-3.20.11.run --noexec
cd hplip-3.20.11
patch -p1 < «path to patch»/evitar_usar_platform.patch
./hplip-install
If you already have hplip installed you can still use this patch. You only have to cd to /usr/share/hplip and then run the patch command above as root.

Revision history for this message
Martin Wilck (mwilck) wrote :

@vivamudhoney, my patch catches the exception that occured in the original code. That remains correct fix IMO. Sorry if it doesn't help you, I have probably missed a special case, or your python version behaves somewhat differently, raising a different exception type than before. A backtrace of the specific problem you observed would be more helpful than your "workaround", which simply skips distribution detection altogether.

Revision history for this message
Felipe Casado (vivamudhoney) wrote :

You are right, Martin. I have tried again with your patch both hp-plugin and hp-toolbox and it has worked. I guess I made a mistake the first time and did not install your patch correctly or something.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.