python3 resource.py: no attribute urlencode error

Bug #1465279 reported by John Agosta
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
launchpadlib
Fix Released
Undecided
Unassigned

Bug Description

I am getting a trace back on

  def _with_url_query_variable_set(self, url, variable, new_value):
        """A helper method to set a query variable in a URL."""
        uri = URI(url)
        if uri.query is None:
            params = {}
        else:
            params = parse_qs(uri.query)
        params[variable] = str(new_value)
        uri.query = urllib.urlencode(params, True) <==== THIS FAILS
        return str(uri)

File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py",
line 853, in __getitem__
    found_slice = self._get_slice(slice(key, key + 1))
File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py",
line 903, in _get_slice
    self._wadl_resource.url, 'ws.start', start)
File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py",
line 976, in _with_url_query_variable_set
    uri.query = urllib.urlencode(params, True)
AttributeError: 'module' object has no attribute 'urlencode'

I am wondering whether it is trying to encode a string when python3 has everything encoded by default - thus the encode function is now invalid.

Revision history for this message
Robert Bruce Park (robru) wrote :

No, this is caused by the urllib module changing API between python2 and python3. The fix is most likely that lazr.restfulclient needs to use six.moves in order to safely import urllib regardless of python version being used.

For now, you can workaround this issue like so:

from urllib.parse import urlencode
from lazr.restfulclient import resource
resource.urllib.urlencode = urlencode

Changed in launchpadlib:
status: New → Confirmed
Revision history for this message
Robert Bruce Park (robru) wrote :

Fixed in xenial.

Changed in launchpadlib:
status: Confirmed → 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.