hp-doctor: UnboundLocalError: local variable 'l' referenced before assignment

Bug #1759278 reported by Chris West
28
This bug affects 5 people
Affects Status Importance Assigned to Milestone
HPLIP
New
Undecided
Unassigned
hplip (Ubuntu)
Confirmed
Undecided
christian

Bug Description

hp-doctor is trying to parse the Python version. Probably other tools are too.

On Python 2, sys.version is "2.7.14+", whos parts cannot be parsed as an integer.
On Python 3, sys.version is "3.6.5rc1", whos parts cannot be parsed as an integer.

Neither of these will work.

% hp-doctor
Traceback (most recent call last):
  File "/usr/bin/hp-doctor", line 42, in <module>
    check_extension_module_env('cupsext')
  File "/usr/share/hplip/base/g.py", line 339, in check_extension_module_env
    python_ver = xint((sys.version).split(' ')[0]) #find the current python version ; xint() to convert string to int, returns a list
  File "/usr/share/hplip/base/g.py", line 331, in xint
    return l
UnboundLocalError: local variable 'l' referenced before assignment

(Note that my printer will only print "Unsupported Personality: UNKNOWN". This is probably an unrelated problem.)

ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: hplip 3.17.10+repack0-5
ProcVersionSignature: Ubuntu 4.15.0-13.14-generic 4.15.10
Uname: Linux 4.15.0-13-generic x86_64
NonfreeKernelModules: nvidia_modeset nvidia
ApportVersion: 2.20.9-0ubuntu1
Architecture: amd64
Date: Tue Mar 27 14:49:56 2018
Lpstat: Error: command ['lpstat', '-v'] failed with exit code 1: lpstat: No destinations added.
MachineType: System manufacturer System Product Name
Papersize: a4
ProcKernelCmdLine: BOOT_IMAGE=/vmlinuz-4.15.0-13-generic.efi.signed root=UUID=672510b8-afb9-425f-a58d-bd325f7c987a ro rootflags=subvol=@ nofb kernel.sysrq=1
SourcePackage: hplip
UpgradeStatus: Upgraded to bionic on 2018-02-19 (35 days ago)
dmi.bios.date: 08/13/2013
dmi.bios.vendor: American Megatrends Inc.
dmi.bios.version: 2104
dmi.board.asset.tag: To be filled by O.E.M.
dmi.board.name: P8Z77-V
dmi.board.vendor: ASUSTeK COMPUTER INC.
dmi.board.version: Rev 1.xx
dmi.chassis.asset.tag: Asset-1234567890
dmi.chassis.type: 3
dmi.chassis.vendor: Chassis Manufacture
dmi.chassis.version: Chassis Version
dmi.modalias: dmi:bvnAmericanMegatrendsInc.:bvr2104:bd08/13/2013:svnSystemmanufacturer:pnSystemProductName:pvrSystemVersion:rvnASUSTeKCOMPUTERINC.:rnP8Z77-V:rvrRev1.xx:cvnChassisManufacture:ct3:cvrChassisVersion:
dmi.product.family: To be filled by O.E.M.
dmi.product.name: System Product Name
dmi.product.version: System Version
dmi.sys.vendor: System manufacturer

Revision history for this message
Chris West (faux) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in hplip (Ubuntu):
status: New → Confirmed
Revision history for this message
Sebastian Piskorski (sebastian.piskorski) wrote :

Workaround is to run command like this:

```
python3 /usr/bin/hp-doctor
```

Revision history for this message
Stdedos (stdedos) wrote :

Same on bionic 18.04:

$ python2 --version
Python 2.7.15rc1

$ sudo hp-doctor -i
Traceback (most recent call last):
  File "/usr/bin/hp-doctor", line 42, in <module>
    check_extension_module_env('cupsext')
  File "/usr/share/hplip/base/g.py", line 340, in check_extension_module_env
    python_ver = xint((sys.version).split(' ')[0]) #find the current python version ; xint() to convert string to int, returns a list
  File "/usr/share/hplip/base/g.py", line 332, in xint
    return l
UnboundLocalError: local variable 'l' referenced before assignment
# Edit: pdb.set_trace()
$ sudo hp-doctor
> /usr/share/hplip/base/g.py(333)xint()
-> return l
(Pdb) ver
'2.7.15rc1'
(Pdb) ver.split('.')
['2', '7', '15rc1']
(Pdb) [int(x) for x in ver.split('.')]
*** ValueError: invalid literal for int() with base 10: '15rc1'
(Pdb)

Code work-around:
# Convert string to int and return a list.
def xint(ver):
    try:
        l = [int(x) for x in ver.split('.')]
    except:
        l = []
        for x in ver.split('.'):
         try:
            l.append(int(x))
         except:
            l.append(None)
    return l

$ sudo hp-doctor
error: cupsext not present in the system. Please re-install HPLIP.

# debug info: [2, 7, None]

Solution for me is `python3 hp-doctor` instead:
$ python3 -VV
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0]

Revision history for this message
Stdedos (stdedos) wrote :

My OS is:
$ lsb_release -a
Distributor ID: LinuxMint
Description: Linux Mint 19 Tara
Release: 19
Codename: tara

christian (richard-foy)
Changed in hplip (Ubuntu):
assignee: nobody → christian (richard-foy)
status: Confirmed → New
Revision history for this message
alain ivars (alainivars) wrote :

I have the same problem as Stdedos (stdedos)

Revision history for this message
alain ivars (alainivars) wrote :

My OS is:
$lsb_release -a 14:39:55
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic

Revision history for this message
rhk (rhk) wrote :

Same problem here:

$ hp-doctor
error: cupsext not present in the system. Please re-install HPLIP.

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=19.04
DISTRIB_CODENAME=disco
DISTRIB_DESCRIPTION="Ubuntu 19.04"

$ sudo apt show hplip
Package: hplip
Version: 3.19.1+dfsg0-1

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in hplip (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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