生成SAP Leonardo API Access Token的python代码

!/usr/bin/env python

-- coding: utf-8 --

import os
import sys

import requests
def get_request_header(xsuaa_base_url, client_id, client_secret):
    response = requests.post(url=xsuaa_base_url + '/oauth/token',
                             data={'grant_type': 'client_credentials',
                                   'client_id': client_id,
                                   'client_secret': client_secret})
    access_token = response.json()["access_token"];
    with open("C:\\Python27\\911.txt", "w") as f:
        f.write(access_token)
        f.close()
    print(access_token);
    
    return {'Authorization': 'Bearer {}'.format(access_token), 'Accept': 'application/json'}


xsuaa_base_url = 'https://jerry.authentication.sap.hana.ondemand.com';
client_id = 'sb-15537af7-4eae-4a5b-b47d-3e6299010b87!b7033|ml-foundation-xsuaa-std!b313';
client_secret = 'jBwKqk5OdUHQKeCgk5EyHoyBJkk=';

print(get_request_header(xsuaa_base_url, client_id, client_secret));

需要修改client_id,secret, token是有时间限制的,需要每次重新生成,

每次生成都写入一个txt里方便使用,

python代码参考链接:https://help.sap.com/viewer/ed8bf217360e4ad7bcbec7707c017a82/1906B/en-US/066e68162d7249bcb4a8b615cdd7e2a3.html

生成SAP Leonardo API Access Token的python代码


上一篇:跟我学SharePoint 2013视频培训课程——什么是SharePoint 2013(1)


下一篇:《分布式系统:概念与设计》一3.3.6 拥塞控制