from rauth import OAuth1Service
OAUTH_REQUEST = "https://bitbucket.org/!api/1.0/oauth/request_token"
OAUTH_AUTH = "https://bitbucket.org/!api/1.0/oauth/authenticate"
OAUTH_ACCESS = "https://bitbucket.org/!api/1.0/oauth/access_token"
service = OAuth1Service(
name='test',
consumer_key='xxxxxxxxxxxxxx',
consumer_secret='xxxxxxxxxxxxxxxxxxxx',
request_token_url=OAUTH_REQUEST,
access_token_url=OAUTH_ACCESS,
authorize_url=OAUTH_AUTH)
resp = service.get_raw_request_token()
print resp
我继续使用Bitbucket并生成了一个消费者密钥对,但回复是400。 知道发生了什么事吗?
我查看了Bitbucket文档,网址是正确的。
修改
感谢@maxcountryman在这里抽出时间。
我刚读了他的linkedlin example code:
import os
from rauth import OAuth1Service
OAUTH_REQUEST = "https://bitbucket.org/!api/1.0/oauth/request_token"
OAUTH_AUTH = "https://bitbucket.org/!api/1.0/oauth/authenticate"
OAUTH_ACCESS = "https://bitbucket.org/!api/1.0/oauth/access_token"
service = OAuth1Service(
name='test',
consumer_key='blah',
consumer_secret='blah',
request_token_url=OAUTH_REQUEST,
access_token_url=OAUTH_ACCESS,
authorize_url=OAUTH_AUTH)
# You can run python -m SimpleHTTPServer if you want a local callback
rtoken, rtoken_secret = service.get_request_token(params={'oauth_callback': 'http://localhost:8000'})
authorize_url = service.get_authorize_url(rtoken)
print 'Visit this URL in your browser: ' + authorize_url
pin = raw_input('Enter PIN from browser: ')
session = service.get_auth_session(rtoken,
rtoken_secret,
data={'oauth_verifier': pin})
reponame = raw_input('Enter the reponame: ')
new_name = raw_input('Enter a new repo name: ')
account_name = raw_input('Enter your account name: ')
url = 'https://api.bitbucket.org/1.0/repositories/%s/%s' %(account_name, reponame)
r = session.put(url, data={'name': new_name})
print r
示例:
(k)yeukhon@yeukhon-P5E-VM-DO:/tmp$ python bb2.py
Visit this URL in your browser: https://bitbucket.org/!api/1.0/oauth/authenticate?oauth_token=xxxxxxxxxxxxx
Enter PIN from browser: 216000000
Enter the reponame: newpatch
Enter a new repo name: junk-patch
Enter your account name: yeukhon
<Response [200]>
修改使用base_url
来获取max的其他建议。
OAUTH_REQUEST = "https://bitbucket.org/!api/1.0/oauth/request_token"
OAUTH_AUTH = "https://bitbucket.org/!api/1.0/oauth/authenticate"
OAUTH_ACCESS = "https://bitbucket.org/!api/1.0/oauth/access_token"
service = OAuth1Service(
name='test',
consumer_key='blah',
consumer_secret='blah',
request_token_url=OAUTH_REQUEST,
access_token_url=OAUTH_ACCESS,
authorize_url=OAUTH_AUTH,
base_url='https://api.bitbucket.org/1.0/')
# You can run python -m SimpleHTTPServer if you want a local callback
rtoken, rtoken_secret = service.get_request_token(params={'oauth_callback': 'http://localhost:8000'})
authorize_url = service.get_authorize_url(rtoken)
print 'Visit this URL in your browser: ' + authorize_url
pin = raw_input('Enter PIN from browser: ')
session = service.get_auth_session(rtoken,
rtoken_secret,
data={'oauth_verifier': pin})
reponame = raw_input('Enter the reponame: ')
new_name = raw_input('Enter a new repo name: ')
account_name = raw_input('Enter your account name: ')
url = 'repositories/%s/%s' %(account_name, reponame)
r = session.put(url, data={'name': new_name})
print r.text
print r
答案 0 :(得分:5)
您需要为API oauth_callback
提供一个,如下所示:
r = service.get_raw_request_token(params={'oauth_callback': 'http://example.com/'})
这应该让你从提供者那里得到适当的回应。