这个问题可能是因为您刚创建了新的自定义密钥,但是尚未在BitBucket中使用它,因此无论哪个用户或应用程序尝试使用它进行身份验证时都会收到“访问权限不正确”的错误消息。要解决这个问题,您需要在BitBucket中的“设置”页面上将新的自定义密钥添加到希望使用它的用户或应用程序的访问密钥列表中。以下是一个示例Python代码,演示如何使用OAuth1访问BitBucket API时正确地使用这个自定义密钥:
import oauthlib.oauth1
import requests
CONSUMER_KEY = 'your consumer key here'
CONSUMER_SECRET = 'your consumer secret here'
OAUTH_TOKEN = 'your oauth token here'
OAUTH_TOKEN_SECRET = 'your oauth token secret here'
# create the oauth1 client
client = oauthlib.oauth1.Client(CONSUMER_KEY, client_secret=CONSUMER_SECRET,
resource_owner_key=OAUTH_TOKEN, resource_owner_secret=OAUTH_TOKEN_SECRET)
# make a request to the BitBucket API using the oauth1 client
response = requests.get('https://api.bitbucket.org/2.0/repositories', auth=client)
# print the response
print(response.json())