avahi.py:64:detectNetworkDevices:ValueError: need more than 1 value to unpack

Bug #1318956 reported by Jiri Popelka
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
HPLIP
Fix Committed
Undecided
Unassigned
Fedora
Fix Released
Undecided

Bug Description

Description of problem:
Set discovery method in hp-toolbox to Avahi

Version-Release number of selected component:
hplip-3.13.11

Traceback (most recent call last):
  File "/usr/share/hplip/ui4/setupdialog.py", line 1232, in NextButton_clicked
    self.showDevicesPage()
  File "/usr/share/hplip/ui4/setupdialog.py", line 563, in showDevicesPage
    filter_dict, self.search, net_search=net_search_type)
  File "/usr/share/hplip/base/device.py", line 496, in probeDevices
    detected_devices = avahi.detectNetworkDevices(ttl, timeout)
  File "/usr/share/hplip/base/avahi.py", line 64, in detectNetworkDevices
    key, value = item.split('=')
ValueError: need more than 1 value to unpack

Local variables in innermost frame:
found_devices: {}
p: <subprocess.Popen object at 0x181a7d0>
ip: '192.168.1.134'
ttl: 4
addr6: []
item: '\n'
addr4: [['192.168.1.134', '0']]
details: ['\n']
timeout: 5
res: [(2, 1, 6, '', ('192.168.1.134', 0)), (2, 2, 17, '', ('192.168.1.134', 0)), (2, 3, 0, '', ('192.168.1.134', 0))]
y: {'note': '', 'mac': '', 'num_devices': 1, 'num_ports': 1, 'product_id': '', 'ip': '192.168.1.134', 'hn': 'Jamess-iMac', 'status_code': 0, 'device3': '0', 'device2': '0'}
line: '=;wlo1;IPv4;HP\\032HP\\032Officejet\\032Pro\\0328500\\032A910\\032\\064\\032James\\226\\128\\153s\\032iMac;_printer._tcp;local;Jamess-iMac.local;192.168.1.134;0;\n'
bits: ['=', 'wlo1', 'IPv4', 'HP\\032HP\\032Officejet\\032Pro\\0328500\\032A910\\032\\064\\032James\\226\\128\\153s\\032iMac', '_printer._tcp', 'local', 'Jamess-iMac.local', '192.168.1.134', '0', '\n']
port: '0'

Revision history for this message
In , James (james-redhat-bugs) wrote :

Description of problem:
Set discovery method in hp-toolbox to Avahi

Version-Release number of selected component:
hplip-3.13.11-4.fc20

Additional info:
reporter: libreport-2.2.2
cmdline: /usr/bin/python /usr/bin/hp-setup -u
dso_list: hplip-gui-3.13.11-4.fc20.x86_64
executable: /usr/bin/hp-setup
kernel: 3.11.10-301.fc20.x86_64
runlevel: N 5
type: Python
uid: 1000

Truncated backtrace:
avahi.py:64:detectNetworkDevices:ValueError: need more than 1 value to unpack

Traceback (most recent call last):
  File "/usr/share/hplip/ui4/setupdialog.py", line 1232, in NextButton_clicked
    self.showDevicesPage()
  File "/usr/share/hplip/ui4/setupdialog.py", line 563, in showDevicesPage
    filter_dict, self.search, net_search=net_search_type)
  File "/usr/share/hplip/base/device.py", line 496, in probeDevices
    detected_devices = avahi.detectNetworkDevices(ttl, timeout)
  File "/usr/share/hplip/base/avahi.py", line 64, in detectNetworkDevices
    key, value = item.split('=')
ValueError: need more than 1 value to unpack

Local variables in innermost frame:
found_devices: {}
p: <subprocess.Popen object at 0x181a7d0>
ip: '192.168.1.134'
ttl: 4
addr6: []
item: '\n'
addr4: [['192.168.1.134', '0']]
details: ['\n']
timeout: 5
res: [(2, 1, 6, '', ('192.168.1.134', 0)), (2, 2, 17, '', ('192.168.1.134', 0)), (2, 3, 0, '', ('192.168.1.134', 0))]
y: {'note': '', 'mac': '', 'num_devices': 1, 'num_ports': 1, 'product_id': '', 'ip': '192.168.1.134', 'hn': 'Jamess-iMac', 'status_code': 0, 'device3': '0', 'device2': '0'}
line: '=;wlo1;IPv4;HP\\032HP\\032Officejet\\032Pro\\0328500\\032A910\\032\\064\\032James\\226\\128\\153s\\032iMac;_printer._tcp;local;Jamess-iMac.local;192.168.1.134;0;\n'
bits: ['=', 'wlo1', 'IPv4', 'HP\\032HP\\032Officejet\\032Pro\\0328500\\032A910\\032\\064\\032James\\226\\128\\153s\\032iMac', '_printer._tcp', 'local', 'Jamess-iMac.local', '192.168.1.134', '0', '\n']
port: '0'

Revision history for this message
In , James (james-redhat-bugs) wrote :

Created attachment 894845
File: backtrace

Revision history for this message
In , James (james-redhat-bugs) wrote :

Created attachment 894846
File: environ

Revision history for this message
In , Jiri (jiri-redhat-bugs) wrote :

Thanks. I've just reported it upstream.

Revision history for this message
Sarbeswar Meher (sarbeswar-meher) wrote :

Can you please provide the output of 'hp-doctor' ? Which version of Fedora are you using?

Revision history for this message
In , Jiri (jiri-redhat-bugs) wrote :

Can you please provide the output of 'hp-doctor' ?

Revision history for this message
goutam (goutamkk) wrote :

Hi Jiri,

Sorry for late reply.
We were able to reproduce this issue and found the cause of it. We will be releasing the fix for this soon.

Thank you & Regards,
Goutam

goutam (goutamkk)
Changed in hplip:
status: New → Fix Committed
Revision history for this message
In , Jiri (jiri-redhat-bugs) wrote :

Fix commited upstream.

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

hplip-3.14.6-1.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/FEDORA-2014-6291/hplip-3.14.6-1.fc20

Revision history for this message
Tim Waugh (twaugh) wrote :

This fix is insufficient.

Changing "item.split('=')" to "item.split('=', 1)" limits the result to a maximum of two list elements, and doesn't have any effect on the actual error: that a singleton list was assumed to have two elements ("need more than 1 value to unpack").

I've attached a patch that really fixes it, as well as some other problems with the parsing code:
* the final key=value... field ends with a newline which was not stripped off
* the de-quoting didn't work for the first or last field

Unfortunately, it still doesn't resolve the ultimate problem that selecting 'Avahi' from the list doesn't work, because another of another error further on:

Searching... (bus=net, timeout=5, ttl=4, search=(None) desc=0, method=avahi)
Traceback (most recent call last):
  File "/usr/share/hplip/ui4/setupdialog.py", line 1229, in NextButton_clicked
    self.showDevicesPage()
  File "/usr/share/hplip/ui4/setupdialog.py", line 562, in showDevicesPage
    filter_dict, self.search, net_search=net_search_type)
  File "/usr/share/hplip/base/device.py", line 496, in probeDevices
    detected_devices = avahi.detectNetworkDevices(ttl, timeout)
  File "/usr/share/hplip/base/avahi.py", line 73, in detectNetworkDevices
    log.debug("ip=%s hn=%s ty=%s" %(ip,y['hn'], y['mdns']))
KeyError: 'mdns'

Here's what avahi-browse actually said:

$ avahi-browse -kprt _printer._tcp | grep ^= | cat -vet
=;wlp3s0;IPv4;Photosmart\0325510\032series\032\091730173\093\032\064\032cyberelk;_printer._tcp;local;cyberelk.local;192.168.0.13;0;$

i.e. bits[9] is '\n'.

It's a shame you didn't attach the fix to this bug report at the time to allow testing of your change, as that would have caught this much sooner. In fact, rather than having to attach patches to each bug report you make a change for, it would probably be easier for you to have a public source code repository to allow interested parties to track changes and flag up problems before they make it into a release.

Had that been the case, I could have raised another issue much earlier still: I think the approach of running 'avahi-browse' and parsing its output is fragile, dangerous, and not appropriate for a graphical application. It is fragile as we have already seen, and prone to changes in the (undocumented, as far as I can tell) output format of avahi-browse. It is dangerous because it makes the assumption that 'avahi-browse' is the binary it expects it to be, not something else the user has in their path. It is not appropriate for a graphical application because execution stops, waiting for avahi-browse to finish, leaving the UI unattended in the meantime.

A much better approach is to use the D-Bus interface org.freedesktop.Avahi.Server. This has a defined API, a well-known location with policy to guarantee it really is Avahi, and is asynchronous. There's an example of how to use the API from Python here: https://git.fedorahosted.org/cgit/system-config-printer.git/tree/dnssdresolve.py (and probably other places).

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

Package hplip-3.14.6-2.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing hplip-3.14.6-2.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-6291/hplip-3.14.6-2.fc20
then log in and leave karma (feedback).

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

hplip-3.14.6-2.fc20 has been pushed to the Fedora 20 stable repository. If problems still persist, please make note of it in this bug report.

Changed in fedora:
importance: Unknown → Undecided
status: Unknown → Fix Released
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.