Spaces:
Build error
Build error
import os | |
import requests | |
def get_token(): | |
username = os.environ["USER_NAME"] | |
domain_name = os.environ["DOMAIN_NAME"] | |
domain_pwd = os.environ["DOMAIN_PWD"] | |
url = os.environ["IAM_URL"] | |
requests_json = { | |
"auth": { | |
"identity": { | |
"methods": ["password"], | |
"password": { | |
"user": { | |
"name": username, | |
"password": domain_pwd, | |
"domain": { | |
"name": domain_name | |
} | |
} | |
} | |
}, | |
"scope": { | |
"project": { | |
"name": "cn-central-221" | |
} | |
} | |
} | |
} | |
headers = { | |
"Content-Type": "application/json" | |
} | |
response = requests.post(url, json=requests_json, headers=headers) | |
result = response.headers | |
print("token success") | |
return result['X-Subject-Token'] | |
if __name__ == "__main__": | |
get_token() | |