这里小编先给大家一个用户的案例,自我感觉有参考价值,如需要更多可私信哦:

#coding=utf-8
import json
import requests
headers={}
headers['Content-Type']='application/json'
headers['Accept']='*/*'
url='http://172.24.111.10:'
url1=url+'35357/v3/auth/tokens'
def get_token():
    body={'auth':{'identity':{'methods':['password'],'password':{'user':{'id':'68225936bb7c428aab19164edc048664','password':'000000'}}},'scope':{'project':{'id':'66b1811ff76b4dab9f083dcee1afe8e3'}}}}
    result=requests.post(url=url1,headers=headers,data=json.dumps(body)).headers['X-Subject-Token']
    return result
headers['X-Auth-Token']=get_token()
url2=url+'35357/v3/users'
def create():
    body={'user':{'name':'testuser','description':'python api','domain_id':'5662c87c08ed4dc0b1f3f35426185341'}}
    result=requests.post(url=url2,headers=headers,data=json.dumps(body)).status_code
    if result ==201:
        print('用户创建成功')
    else:
        print('失败')
create()

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐