butler_ddochi/nhncloud/packages/ApiToken.py
icurfer ea11832a53
Some checks failed
Build And Test / build-and-push (push) Failing after 53s
init
2024-12-13 17:12:03 +09:00

42 lines
1.1 KiB
Python

import requests
import json
# def createToken(url, parms):
def createToken(parms):
url = "https://api-identity-infrastructure.nhncloudservice.com/v2.0/tokens"
response = requests.post(url, json=parms) # 응답요청
datas = json.loads(response.text)
# print(datas)
if "error" in datas:
errDict = {
'state' : 'err',
'code' : datas['error']['code'],
'errTitle' : datas['error']['title'],
'errMsg' : datas['error']['message']
}
return errDict
else:
getDict = {
'state' : 'steady',
'tokenValue' : datas['access']['token']['id']
}
# WhatToken = getDict['tokenValue']
return getDict
if __name__ == "__main__":
# 예제 내용
url = "https://api-identity-infrastructure.nhncloudservice.com/v2.0/tokens"
parms = {
"auth": {
"tenantId": "04a2c5b7de7e4d66b970ad950081a7c3", # kr2
"passwordCredentials": {
# "username": "sdjo@injeinc.co.kr",
# "password": "ijinc123!"
}
}
}
print(createToken(url, parms))