Python 类型错误:';HMAC&x27;对象不可调用

Python 类型错误:';HMAC&x27;对象不可调用,python,hmac,Python,Hmac,当通过下列程序时: hmac.new(secretkey.encode(), sig1.encode(), sha1) 我收到以下错误 TypeError:“HMAC”对象不可调用 我相信这对大多数人来说都是基本的,但我刚刚开始接触python,这让我有点头疼 有人能帮助解释或解决这个问题吗 更多信息请按要求提供 url = "https://api.twitter.com/1.1/search/tweets.json?q=something" # url = "https://google

当通过下列程序时:

hmac.new(secretkey.encode(), sig1.encode(), sha1)
我收到以下错误

TypeError:“HMAC”对象不可调用

我相信这对大多数人来说都是基本的,但我刚刚开始接触python,这让我有点头疼

有人能帮助解释或解决这个问题吗

更多信息请按要求提供

url = "https://api.twitter.com/1.1/search/tweets.json?q=something"  # url = "https://google.com"
realurl = "https://api.twitter.com/1.1/search/tweets.json"
http_method = "GET"
oauth_consumer_key = "removed"
oauth_token = "removed"
oauth_signature_method = "HMAC-SHA1"
oauth_timestamp = "1430882576"
oauth_nonce = "pISS1c"
oauth_version = "1.0"
oauth_signature = "removed"
oauth_consumer_secret_key = "removed"


class TwitterModel:
    def SignitureGenerator():

    from urllib.parse import quote
    import binascii
    import hmac
    from hashlib import sha1

    secretkey = quote(oauth_consumer_secret_key, '')+"&"+quote(oauth_token_secret, '')

    sig1 = realurl+"&oauth_consumer_key="+oauth_consumer_key+"&oauth_nonce="+oauth_nonce+"&26oauth_signature_method="+oauth_signature_method+"&oauth_timestamp="+oauth_timestamp+"&oauth_token="+oauth_token+"&oauth_version="+oauth_version

    sig1 = "GET&"+quote(sig1, '')

    hashkey = hmac.new(secretkey.encode(), sig1.encode(), sha1)

    return hashkey
回溯


通过在hmac.new中添加.digest()似乎解决了这个问题

hashkey = hmac.new(secretkey.encode(), sig1.encode(), sha1).digest()

需要更多的代码。。。您是否重新分配了
hmac
或直接导入了它?您是否尝试执行类似
hmac.new(secretkey.encode(),sig1.encode(),sha1)(
)的操作?仍然不是您真正的代码,
返回没有任何函数体的
语句?代码看起来不错,无论谁接收从
SignitureGenerator
返回的
hashkey
,实际上都在试图调用它,这是不正确的。@cusackBOOM检查或发布整个回溯,它将告诉您哪个部分正试图调用
hashkey
hashkey = hmac.new(secretkey.encode(), sig1.encode(), sha1).digest()