华为云人脸识别api token获取

  1. 具体的步骤这里有比较详细的:https://support.huaweicloud.com/api-face/face_02_0029.html
  2. Token在计算机系统中代表令牌(临时)的意思,拥有Token就代表拥有某种权限。Token认证就是在调用API的时候将Token加到请求消息头,从而通过身份认证,获得操作API的权限。username为用户名,domainname为用户所属的账号名称,********为用户登录密码,project name为项目名称。username,domainname和project name的获取方法参见获取用户名、用户ID、项目名称、项目ID。获取Token时,如果出现帐密报错“The username or password is wrong.”,请参见如何处理帐密报错。获取Token的终端节点和project name需与FRS服务终端节点保持一致。当访问华北-北京四的终端节点(即访问https://face.cn-north-4.myhuaweicloud.com时),获取Token请使用终端节点https://iam.cn-north-4.myhuaweicloud.com,project name为cn-north-4。
# -*- coding: utf-8 -*-#
# -------------------------------------------------------------------------------
# Name:         获取token
# Author:       yunhgu
# Date:         2022/2/15 16:29
# Description: 
# -------------------------------------------------------------------------------
import requests

url = "https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens"
request_body = {
    "auth": {
        "identity": {
            "methods": [
                "password"
            ],
            "password": {
                "user": {
                    "name": "xxx",
                    "password": "xxx",
                    "domain": {
                        "name": "xxx"
                    }
                }
            }
        },
        "scope": {
            "project": {
                "name": "cn-north-1"
            }
        }
    }
}

r = requests.post(url, json=request_body)
print(r.status_code)
print(r.headers.get("X-Subject-Token"))

posted @ 2022-02-22 09:27  不能说的秘密  阅读(292)  评论(0编辑  收藏  举报