即使不再使用它來支持 UTC,我嘗試查詢的端點(diǎn)也需要帶有以下格式的日期標(biāo)頭的 hmac 簽名:"Sun, 22 Sep 2019 09:18:13 GMT"這種不推薦使用的方法new Date().toGMTString();使 js sdk 工作,我需要 python 中的等價(jià)物。time.strftime("%a, %d %b %Y %I:%M:%S %Z", time.gmtime())time.strftime("%a, %d %b %Y %I:%M:%S %z", time.gmtime())在返回時(shí)返回全名(即中歐時(shí)間)"Sun, 22 Sep 2019 09:18:13 +0100"。我得到的最接近的是time.strftime("%a, %d %b %Y %I:%M:%S GMT", time.gmtime())理論上打印正確的字符串,但無論如何我都會(huì)收到這個(gè)錯(cuò)誤:"{\"message\":\"HMAC signature cannot be verified, a valid date or x-date header is required for HMAC Authentication\"}"
2 回答
鴻蒙傳說
TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
看看這里: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"))
添加回答
舉報(bào)
0/150
提交
取消
