Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not work with secret #26

Open
ionoff opened this issue Jul 9, 2017 · 4 comments
Open

not work with secret #26

ionoff opened this issue Jul 9, 2017 · 4 comments

Comments

@ionoff
Copy link

ionoff commented Jul 9, 2017

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'
@fvanderbiest
Copy link
Contributor

confirmed here too.

@ygini
Copy link

ygini commented Aug 23, 2017

The same here

@ygini
Copy link

ygini commented Aug 23, 2017

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:

@richsuca
Copy link

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)

Sancus pushed a commit to thunderbird/python-github-webhooks that referenced this issue May 18, 2023
…actions/docker/login-action-1.13.0

Bump docker/login-action from 1.12.0 to 1.13.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants