开发者社区> 问答> 正文

API获取域名列表一直AuthFailure,code:4100?

import hmac import hashlib import json import requests import time from hashlib import sha1 import base64 from urllib.parse import quote with open("config.json") as config_file: config = json.load(config_file)
uri = "cns.api.qcloud.com/v2/index.php?" SecretId = config["SecretId"] SecretKey = config["SecretKey"]

所需要的参数

param_dict = { "Action": "DomainList", "Nonce": "233333", "SecretId": SecretId, "Timestamp": str(int(time.time()))

}

生成请求字符串

result_str = ("Action=" + param_dict["Action"] + "&Nonce="+param_dict["Nonce"] + "&SecretId="+param_dict["SecretId"] + "&Timestamp="+param_dict["Timestamp"] )

拼接签名原文字符串

requestStr = "GET"+uri+result_str

签名

signStr = requestStr.encode("UTF-8") SecretKey = SecretKey.encode("UTF-8") hashed = hmac.new(SecretKey, signStr, sha1).hexdigest()

base64加密,同时进行URL编码

base64Data = quote(base64.b64encode(hashed.encode("utf-8")))

data = requests.get("https://"+uri+result_str+"&Signature="+base64Data).text print(data)

-------------------输出------------------

{

"code":4100,

"message":"\u8eab\u4efd\u8ba4\u8bc1\u5931\u8d25

\uff0c\u7528\u6237\u8eab\u4efd\u9a8c\u8bc1\u5931\u8d25",

"codeDesc":"AuthFailure"

}

------------------------------------------

展开
收起
北藏有名 2020-02-06 17:03:13 1363 0
1 条回答
写回答
取消 提交回答
  • 有点尴尬唉 你要寻找的东西已经被吃掉啦!

    推荐使用SDK进行调用:https://github.com/QcloudApi/qcloudapi-sdk-python

    如果要自己写,也请参考下签名文档中python的代码示例,或者SDK中的源码:https://github.com/QcloudApi/qcloudapi-sdk-python/blob/master/QcloudApi/common/sign.py

    API2.0不再推荐使用了,请尽量用API3.0吧

    2020-02-06 17:03:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Boot2.0实战Redis分布式缓存 立即下载
CUDA MATH API 立即下载
API PLAYBOOK 立即下载