【问题标题】:AttributeError: HMAC instance has no attribute '__len__' pythonAttributeError:HMAC 实例没有属性“__len__”python
【发布时间】:2018-03-21 08:16:14
【问题描述】:

目前正在为 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()

关于是什么原因造成的任何想法?在编码中总是这样。我们一无所有 -_-

【问题讨论】:

    标签: amazon-s3 hex sha256 hmac attributeerror


    【解决方案1】:
    signingkey = hmac.new(dateregionservicekey, "aws4_request").digest()
    

    否则 signingkey 是一个 hmac 对象

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 2015-03-22
      • 2013-10-05
      • 1970-01-01
      • 2013-04-30
      • 1970-01-01
      • 2013-01-09
      相关资源
      最近更新 更多