对于 python 中的 CouchDB OAuth 示例,您可以使用wiki 页面中有关 OAuth 授权的脚本。
但是,由于它是以单行样式编写的,因此这里是流版本:
import oauth
import httplib
URL='http://localhost:5984/_session'
CONSUMER_KEY = 'example.com'
CONSUMER_SECRET = 'sekr1t'
TOKEN='user1'
SECRET='tokensekr1t'
consumer = oauth.OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET)
token = oauth.OAuthToken(TOKEN, SECRET)
req = oauth.OAuthRequest.from_consumer_and_token(
consumer, token=token, http_method='GET', http_url=URL, parameters={}
)
req.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(), consumer,token)
con = httplib.HTTPConnection('localhost', 5984)
con.request('GET', URL,headers=req.to_header())
print con.getresponse().read()