我正在尝试从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型。凭证不完整或格式错误。 如有任何建议,不胜感激。在
先拿到你的证件:
转到https://developer.sabre.com/apps/mykeys并获取您的凭据。它们应该是这样的(垃圾邮件和鸡蛋看起来像垃圾):
然后调用
^{pr2}$/v2/auth/token
端点以获取访问令牌:你应该得到这样的东西:
现在,您可以使用包含您的访问令牌的
Authorization
头来调用其他端点。例如,如果您想要支持的国家/地区列表:如果一切顺利,您将收到受支持国家的名单:
{oauth}尽管命名为oauth}库,但它确实不能实现。这里是我能找到的最好的库,它提供OAuth 2支持并有文档:http://requests-oauthlib.readthedocs.org/en/latest/oauth2_workflow.html
我不能使用oauth2,但我使用了requests包I think you can get it from here
我的代码是:
谨致问候
相关问题 更多 >
编程相关推荐