0

I'm having a hard time with the changes made to the Rauth library and I was wondering of anybody could help.

First I create a Rauth wrapper as such (this is merely an example, not my actual code):

service = OAuth2Service(
           name='example',
           client_id='123',
           client_secret='456',
           access_token_url='https://example.com/token',
           authorize_url='https://example.com/authorize',
           base_url='https://example.com/api/')

I then do the authorization correctly and it returns a token, I then use that access_token to make a session. The access token is present, I checked.

session = service.get_session(token['access_token'])

Problem is that when I got to make a query, I get back that my session is invalid.

self.session.get(some url, params = self.params, timeout = 30.0).content)

self.params = {'Authorization': 'Bearer ' + self.access_token}

I'm not sure if I'm using the library right with the new changes. Any ideas? I also don't know how to check if a session is valid or not, so that could help too.

  • Please give us the full traceback. – maxcountryman Apr 26 '13 at 02:38
  • I fixed part of it. My main problem now is that it's returning something like: {"totalSize":1,"done":true,"records":[{"attributes":{"type":"My_Pets__c","url":"/services/data/v20.0/sobjects/My_Pets__c/*********"},"Id":"*********"}]} I'm trying to access it the normal way you would access a dictionary, results['records'] and I get an error like this: TypeError: string indices must be integers, not str. When I try to convert it to JSON to access it like that I get AttributeError: 'str' object has no attribute 'json' –  Apr 26 '13 at 02:47
  • That's because it's returning a JSON string. Try this: `data = session.get(...).json()`. – maxcountryman Apr 26 '13 at 02:49
  • Unfortunately I still get the error. Here's part of the trace back: self.session.get(elements, headers = self.header_items, timeout = 30.0).content).json() AttributeError: 'str' object has no attribute 'json' –  Apr 26 '13 at 02:54
  • You need to not use the `content` attribute, use the `json()` getter instead. Replace `content` with `json()` and it will work. – maxcountryman Apr 26 '13 at 02:55
  • Thank you very much Max, it works now. Your library is wonderful by the way, seriously. –  Apr 26 '13 at 02:58
  • 1
    Cool, glad you got it! – maxcountryman Apr 26 '13 at 03:02

1 Answers1

0

For those of you looking for help migrating to rauth 0.5.x, please refer to the upgrade guide.

maxcountryman
  • 1,562
  • 1
  • 24
  • 51