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()
base64Data = quote(base64.b64encode(hashed.encode("utf-8")))
data = requests.get("https://"+uri+result_str+"&Signature="+base64Data).text print(data)
推荐使用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吧
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。