TypeError calling sharing service getPillarGranteeData

Bug #1040913 reported by Curtis Hovey
4
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
Triaged
Critical
Unassigned

Bug Description

This example of API
    service = lp.load('/+services/sharing')
    service.getPillarGranteeData(pillar=project)

Raise a TypeError error because wadllib resource.url returned a URI instead a string
Traceback (most recent call last):
  File "./share-projects-with-team.py", line 106, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./share-projects-with-team.py", line 102, in main
    migrator.share()
  File "./share-projects-with-team.py", line 39, in share
    self.unshare_with_team_members()
  File "./share-projects-with-team.py", line 68, in unshare_with_team_members
    grantees = self.service.getPillarGranteeData(pillar=self.project)
  File "/usr/lib/python2.7/dist-packages/lazr/restfulclient/resource.py", line 563, in __call__
    url = self.wadl_method.build_request_url(**args)
  File "/usr/lib/python2.7/dist-packages/wadllib/application.py", line 615, in build_request_url
    return self.request.build_url(param_values, **kw_param_values)
  File "/usr/lib/python2.7/dist-packages/wadllib/application.py", line 731, in build_url
    if '?' in url:
TypeError: argument of type 'URI' is not iterable

Revision history for this message
Curtis Hovey (sinzui) wrote :

This is the hack in my script to allow me to use this method:
# Every normal man must be tempted at times to spit on his hands,
# hoist the black flag, and begin to slit throats.
def safe_build_url(self, param_values=None, **kw_param_values):
    """Return the request URL to use to invoke this method.

    The unsafe method raises an error for
    lp.load('/+services/sharing')
    because the wadl resource.uri it gets a URI instead of a str.
    """
    try:
        from urllib.parse import urlencode
        urlencode
    except ImportError:
        from urllib import urlencode
    validated_values = self.validate_param_values(
        self.query_params, param_values, **kw_param_values)
    url = str(self.resource.url)
    if len(validated_values) > 0:
        if '?' in url:
            append = '&'
        else:
            append = '?'
        url += append + urlencode(validated_values)
    return url

Revision history for this message
Curtis Hovey (sinzui) wrote :

This is the example script that where I call the method. It also contains the hack to wadllib.

Revision history for this message
Curtis Hovey (sinzui) wrote :

This bug is really a dupe of Bug #681767. We might want to explore fixing this bug in launchpad instead of lazr.restfulclient or wadllib.

Revision history for this message
Curtis Hovey (sinzui) wrote :

This work because the full URL is used to load the service.
    service = lp.load('https://api.launchapd.net/devel/+services/sharing')
    service.getPillarGranteeData(pillar=project)

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.