python-github-webhooks
python-github-webhooks copied to clipboard
not work with secret
trafficstars
File "/app/webhooks.py", line 82, in index
mac = hmac.new(str(secret), msg=request.data, digestmod='sha1')
File "/usr/local/lib/python2.7/hmac.py", line 136, in new
return HMAC(key, msg, digestmod)
File "/usr/local/lib/python2.7/hmac.py", line 52, in __init__
self.outer = self.digest_cons()
File "/usr/local/lib/python2.7/hmac.py", line 50, in <lambda>
self.digest_cons = lambda d='': digestmod.new(d)
AttributeError: 'str' object has no attribute 'new'
confirmed here too.
The same here
Here is the fix
--- a/webhooks.py
+++ b/webhooks.py
@@ -79,7 +79,7 @@ def index():
abort(501)
# HMAC requires the key to be bytes, but data is string
- mac = hmac.new(str(secret), msg=request.data, digestmod='sha1')
+ mac = hmac.new(str(secret), msg=request.data, digestmod=sha1)
# Python prior to 2.7.7 does not have hmac.compare_digest
if hexversion >= 0x020707F0:
I was still getting below error (FreeBSD)
File "webhooks.py", line 87, in index
mac = hmac.new(str(secret), msg=request.data, digestmod=sha1)
File "/usr/local/lib/python3.7/hmac.py", line 153, in new
return HMAC(key, msg, digestmod)
File "/usr/local/lib/python3.7/hmac.py", line 49, in __init__
raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__)
TypeError: key: expected bytes or bytearray, but got 'str'
Go it to work with
mac = hmac.new(secret.encode('utf-8'), msg=request.data, digestmod=sha1)