我正在尝试从 Sabre Dev Studio 获取身份验证令牌。我遵循此处给出的通用说明https://developer.sabre.com/docs/read/rest_basics/authentication(需要登录才能查看),但我无法弄清楚如何使用 Python 获取令牌 - 特别是使用 python- oauth2 库,因为似乎建议简化该过程。
这是我的代码示例:
config = ConfigParser.ConfigParser()
config.read("conf.ini")
clientID = config.get('DEV', 'Key').strip()
clientSecret = config.get('DEV', 'SharedSecret').strip()
consumer = oauth.Consumer(key=base64.b64encode(clientID),
secret=base64.b64encode(clientSecret))
# Request token URL for Sabre.
request_token_url = "https://api.sabre.com/v1/auth/token"
# Create our client.
client = oauth.Client(consumer)
# create headers as per Sabre Dev Guidelines https://developer.sabre.com/docs/read/rest_basics/authentication
headers = {'Content-Type':'application/x-www-form-urlencoded'}
params = {'grant_type':'client_credentials'}
# The OAuth Client request works just like httplib2 for the most part.
resp, content = client.request(request_token_url, "POST", headers=headers)
print resp
print content
响应为 401 类型。凭据不完整或格式错误。任何建议表示赞赏。