Rauth不使用requests_cache

时间:2014-09-29 01:57:02

标签: python python-requests rauth

尝试使用requests_cache来利用猴子修补的Session,维护一个持久存储的响应,Rauth OAuth1Session似乎不会很好。

假设钥匙已在别处设置......

import requests
import requests_cache
requests_cache.install_cache('test-cache', backend='sqlite', expire_after=300)
from rauth.session import OAuth1Session

session = OAuth1Session(consumer_key=CONSUMER_KEY,
    consumer_secret=CONSUMER_SECRET,
    access_token=ACCESS_TOKEN,
    access_token_secret=ACCESS_SECRET)
r = session.get("http://www.paperbackswap.com/api/v2/index.php", params={"RequestType": "MemberData"});

结果:

>  File "run.py", line 5, in <module>
>    from rauth.session import OAuth1Session
>  File "/Users/jasharmon/src/oauth_1.0a_tool/venv/lib/python2.7/site-packages/rauth/__init__.py", line 22, in <module>
>    from .service import OAuth1Service, OAuth2Service, OflyService
>  File "/Users/jasharmon/src/oauth_1.0a_tool/venv/lib/python2.7/site-packages/rauth/service.py", line 10, in <module>
>    from rauth.session import OAuth1Session, OAuth2Session, OflySession
>  File "/Users/jasharmon/src/oauth_1.0a_tool/venv/lib/python2.7/site-packages/rauth/session.py", line 28, in <module>
>    class RauthSession(Session):
>  File "/Users/jasharmon/src/oauth_1.0a_tool/venv/lib/python2.7/site-packages/rauth/session.py", line 29, in RauthSession
>    __attrs__ = Session.__attrs__ + ['service']
>AttributeError: 'function' object has no attribute '__attrs__'

1 个答案:

答案 0 :(得分:2)

仅供参考,因为requests_cache使用了lambda来修补补丁。修正了这里: https://github.com/reclosedev/requests-cache/issues/28