daxiang28
daxiang28

Reputation: 553

Rauth __attrs__ with OAuth2Service.get_session

Having problems with Rauth (or Reqeuests) Oauth2 session usage. Hope the code and error below makes sense.

Thanks, Steve

Error Message: 'OAuth2Session' object has no attribute '__attrs__'

Code:

self.auth_service = OAuth2Service(
  name=self.PARSER_NAME,
  client_id=self.CLIENT_ID,
  client_secret=self.CLIENT_SECRET,
  access_token_url=self.ACCESS_TOKEN_URL,
  authorize_url=self.AUTHORIZE_URL,
  base_url=self.BASE_URL,
)   
    session = self.auth_service.get_session(token=token_data["access_token"])
    # I tried this as an alternate way to get the session with same results
    #session = OAuth2Session(self.CLIENT_ID, self.CLIENT_SECRET, access_token=token_data["access_token"])
    self.request.session['oauth_session'] = session 

Error:

    Request Method: GET
Request URL:    http://example.com/parsers/login/moves/?code=Apdo3m7m3nEA64rUW0cof85Sq6Lp_Aua4HB_Hd0QJXvWqpf1JeXSNDIt1wEdBYSy&state=
Django Version: 1.4.3
Exception Type: AttributeError
Exception Value:    
'OAuth2Session' object has no attribute '__attrs__'
Exception Location: /Library/Python/2.7/site-packages/requests/sessions.py in __getstate__, line 397
Python Executable:  /usr/bin/python
Python Version: 2.7.2
Python Path:    
['/Library/Python/2.7/site-packages/pip-1.2.1-py2.7.egg',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages',
 '/Projects/motiv8/']
Server time:    Tue, 11 Jun 2013 11:32:16 -0700

Looks like it traces back to the requests sessions:

/Library/Python/2.7/site-packages/requests/sessions.py in __getstate__
    return dict((attr, getattr(self, attr, None)) for attr in self.__attrs__) 

Upvotes: 0

Views: 985

Answers (1)

daxiang28
daxiang28

Reputation: 553

@maxcountryman helped me answer this over at the GitHub issue tracker. A simple update of Requests from 1.1.0 to 1.2.3 was the fix. I guess a pip install rauth --upgrade didn't trigger the update for requests

Upvotes: 3

Related Questions