AttributeError: HMAC instance has no attribute '__len__' python

AttributeError: HMAC instance has no attribute '__len__' python

目前正在为 AWS s3 签名。在我计算签名的最后一个哈希上,出现以下错误:

 signature = hmac.new(signingkey, policy, hashlib.sha256).digest()
  File "/usr/lib/python2.7/hmac.py", line 136, in new
    return HMAC(key, msg, digestmod)
  File "/usr/lib/python2.7/hmac.py", line 71, in __init__
    if len(key) > blocksize:
AttributeError: HMAC instance has no attribute '__len__'

代码:

datekey = hmac.new(str("AWS4") + AWS_UPLOAD_SECRET_KEY,stringdate , hashlib.sha256).digest()
            dateregionkey = hmac.new(datekey, AWS_UPLOAD_REGION, hashlib.sha256).digest()
            dateregionservicekey = hmac.new(dateregionkey,"s3", hashlib.sha256).digest()
            signingkey = hmac.new(dateregionservicekey, "aws4_request")
            signature = hmac.new(signingkey, policy, hashlib.sha256).digest()

知道是什么原因造成的吗?在编码中总是这样。我们什么都免费 -_-

signingkey = hmac.new(dateregionservicekey, "aws4_request").digest()

否则signingkey是一个hmac对象