davidchua / pymessenger

A Python Wrapper for the FB Messenger Bot API (Send/Receive API)
MIT License
457 stars 183 forks source link

`unicode` is not defined in python 3 #53

Open ottonemo opened 6 years ago

ottonemo commented 6 years ago

In utils.py there is still one line that uses unicode() which will fail in python3. Patch:

@@ -17,7 +17,10 @@ def validate_hub_signature(app_secret, r
         pass
     else:
         digest_module = getattr(hashlib, hash_method)
-        hmac_object = hmac.new(str(app_secret), unicode(request_payload), digest_module)
+        if six.PY2:
+                hmac_object = hmac.new(str(app_secret), unicode(request_payload), digest_module)
+        else:
+                hmac_object = hmac.new(bytearray(app_secret, 'utf8'), request_payload, digest_module)
         generated_hash = hmac_object.hexdigest()
         if hub_signature == generated_hash:
             return True