即使不再使用它来支持 UTC,我尝试查询的端点也需要带有以下格式的日期标头的 hmac 签名:"Sun, 22 Sep 2019 09:18:13 GMT"这种不推荐使用的方法new Date().toGMTString();使 js sdk 工作,我需要 python 中的等价物。time.strftime("%a, %d %b %Y %I:%M:%S %Z", time.gmtime())time.strftime("%a, %d %b %Y %I:%M:%S %z", time.gmtime())在返回时返回全名(即中欧时间)"Sun, 22 Sep 2019 09:18:13 +0100"。我得到的最接近的是time.strftime("%a, %d %b %Y %I:%M:%S GMT", time.gmtime())理论上打印正确的字符串,但无论如何我都会收到这个错误:"{\"message\":\"HMAC signature cannot be verified, a valid date or x-date header is required for HMAC Authentication\"}"
2 回答
![?](http://img1.sycdn.imooc.com/54584ef20001deba02200220-100-100.jpg)
鸿蒙传说
TA贡献1865条经验 获得超7个赞
看看这里:https ://www.programiz.com/python-programming/datetime/strftime
确保您使用%Z 而不是 %z。
from datetime import datetime
import time
now = datetime.now() # current date and time
date_time = time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.gmtime())
# output: date and time: Sun, 22 Sep 2019 10:01:53 GMT
print("date and time in GMT:",date_time)
# output: Local: Sun, 22 Sep 2019 10:01:53 AM UTC
print("Local: " + time.strftime("%a, %d %b %Y %I:%M:%S %p %Z\n"))
添加回答
举报
0/150
提交
取消