Spaces:
Runtime error
Runtime error
File size: 1,123 Bytes
7a6c4ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import os
import requests
def get_token():
username = os.environ["username"]
domain_name = os.environ["domain_name"]
domain_pwd = os.environ["domain_pwd"]
url = "https://iam.cn-central-221.myhuaweicloud.com/v3/auth/tokens"
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": "text/plain"
}
response = requests.post(url, json=requests_json, headers=headers)
assert response.status_code == 201
result = response.headers
print("token success")
return result['X-Subject-Token']
if __name__ == "__main__":
get_token()
|