遇到Rauth(或Reqeuests)Oauth2会话使用问题。希望下面的代码和错误是有道理的。
谢谢, 史蒂夫
错误讯息:
'OAuth2Session' object has no attribute '__attrs__'
代码:
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
错误:
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
看起来它追溯到请求会话:
/Library/Python/2.7/site-packages/requests/sessions.py in __getstate__
return dict((attr, getattr(self, attr, None)) for attr in self.__attrs__)
答案 0 :(得分:3)
pip install rauth --upgrade
没有触发请求更新