Merge lp:~mbp/txrestfulclient/trivial into lp:txrestfulclient

Proposed by Martin Pool
Status: Merged
Merged at revision: 42
Proposed branch: lp:~mbp/txrestfulclient/trivial
Merge into: lp:txrestfulclient
Diff against target: 81 lines (+16/-4)
5 files modified
examples/lp_print_me.py (+2/-0)
txrestfulclient/__init__.py (+3/-1)
txrestfulclient/browser.py (+5/-0)
txrestfulclient/launchpad/__init__.py (+4/-1)
txrestfulclient/launchpad/credentials.py (+2/-2)
To merge this branch: bzr merge lp:~mbp/txrestfulclient/trivial
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+34944@code.launchpad.net

Description of the change

On maverick trying to create a new token fails as follows:

  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 891, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/usr/lib/python2.6/dist-packages/twisted/python/failure.py", line 338, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "examples/lp_print_me.py", line 32, in print_me
    service_root=EDGE_SERVICE_ROOT, cache=cache)
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 441, in _runCallbacks
    self.result = callback(self.result, *args, **kw)
  File "/home/mbp/work/txrestfulclient/trunk/txrestfulclient/launchpad/__init__.py", line 166, in get_access_token
    credentials.exchange_request_token_for_access_token(web_root)
  File "/home/mbp/work/txrestfulclient/trunk/txrestfulclient/launchpad/credentials.py", line 112, in exchange_request_token_for_access_token
    data=urlencode(params))
  File "/usr/lib/python2.6/dist-packages/twisted/web/client.py", line 539, in getPage
    *args, **kwargs).deferred
  File "/usr/lib/python2.6/dist-packages/twisted/web/client.py", line 515, in _makeGetterFactory
    factory = factoryFactory(url, *args, **kwargs)
exceptions.TypeError: __init__() got an unexpected keyword argument 'data'

Perhaps it was renamed in twisted 10.1, or perhaps it never worked?

To post a comment you must log in.
lp:~mbp/txrestfulclient/trivial updated
43. By Martin Pool

Turn on twisted debugging

44. By Martin Pool

Better message for RequestFailed exception

45. By Martin Pool

Must wait for access token to actually be obtained before using it

46. By Martin Pool

Stash credentials into ServiceRoot object; they seem to be needed there

Revision history for this message
Martin Pool (mbp) wrote :

This fixes a few more things to get lp_print_me working, in particular

52 - credentials.exchange_request_token_for_access_token(web_root)
53 + d = credentials.exchange_request_token_for_access_token(web_root)
54 + d.addCallback(build_service_root)
55 + return d
56 + def build_service_root(ignored):
57 return cls.from_url(service_root, credentials)

This wasn't actually waiting for exchange_request_token_for_access_token to run!

Revision history for this message
James Westby (james-w) wrote :

Looks good, thanks.

James

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

Thanks for the prompt review.

At the moment the trunk is owned by you so you'll need to merge it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/lp_print_me.py'
2--- examples/lp_print_me.py 2010-04-23 18:37:17 +0000
3+++ examples/lp_print_me.py 2010-09-09 05:29:38 +0000
4@@ -17,6 +17,8 @@
5 cache = DesktopCouchCache(db)
6 d = db.createDB()
7
8+ defer.setDebugging(True)
9+
10 def ignore_existing(err):
11 err.trap(twisted.web.error.Error)
12 if err.value.status != "412":
13
14=== modified file 'txrestfulclient/__init__.py'
15--- txrestfulclient/__init__.py 2010-04-23 18:37:17 +0000
16+++ txrestfulclient/__init__.py 2010-09-09 05:29:38 +0000
17@@ -968,7 +968,9 @@
18 def handle_response(response_and_body):
19 resp, body = response_and_body
20 bound_root = root_resource.bind(body, 'application/json')
21- return klass(root_uri, app, bound_root, browser)
22+ sr = klass(root_uri, app, bound_root, browser)
23+ sr.credentials = credentials
24+ return sr
25 return d.addCallback(handle_response)
26 d.addCallback(create_object)
27 return d
28
29=== modified file 'txrestfulclient/browser.py'
30--- txrestfulclient/browser.py 2010-04-23 18:37:17 +0000
31+++ txrestfulclient/browser.py 2010-09-09 05:29:38 +0000
32@@ -260,6 +260,11 @@
33 self.response = response
34 self.body = body
35
36+ def __str__(self):
37+ return ("txrestfulclient browser request failed: "
38+ "response body:\n-----\n%s\n-----" % (
39+ self.body))
40+
41
42 def transform_error(response_and_body):
43 resp, body = response_and_body
44
45=== modified file 'txrestfulclient/launchpad/__init__.py'
46--- txrestfulclient/launchpad/__init__.py 2010-04-23 18:37:17 +0000
47+++ txrestfulclient/launchpad/__init__.py 2010-09-09 05:29:38 +0000
48@@ -163,7 +163,10 @@
49 authorization_json['oauth_token'], allow_access_levels,
50 max_failed_attempts)
51 authorizer()
52- credentials.exchange_request_token_for_access_token(web_root)
53+ d = credentials.exchange_request_token_for_access_token(web_root)
54+ d.addCallback(build_service_root)
55+ return d
56+ def build_service_root(ignored):
57 return cls.from_url(service_root, credentials)
58 d.addCallback(get_access_token)
59 return d
60
61=== modified file 'txrestfulclient/launchpad/credentials.py'
62--- txrestfulclient/launchpad/credentials.py 2010-04-23 18:37:17 +0000
63+++ txrestfulclient/launchpad/credentials.py 2010-09-09 05:29:38 +0000
64@@ -67,7 +67,7 @@
65 if token_format == self.DICT_TOKEN_FORMAT:
66 headers['Accept'] = 'application/json'
67 d = twisted.web.client.getPage(url, method='POST',
68- headers=headers, data=urlencode(params))
69+ headers=headers, postdata=urlencode(params))
70 def handle_response(content):
71 if token_format == self.DICT_TOKEN_FORMAT:
72 params = simplejson.loads(content)
73@@ -109,7 +109,7 @@
74 oauth_signature='&%s' % self._request_token.secret)
75 url = web_root + lplib_credentials.access_token_page
76 d = twisted.web.client.getPage(url, method='POST',
77- data=urlencode(params))
78+ postdata=urlencode(params))
79 def handle_response(content):
80 self.access_token = lplib_credentials.AccessToken.from_string(content)
81 d.addCallback(handle_response)

Subscribers

People subscribed via source and target branches

to all changes: