# Webhook signature validation - Python

**URL:** <https://www.patreondevelopers.com/t/webhook-signature-validation-python/441>\
**Category:** API Feedback\
**Created:** [April 5, 2018, 2:12pm UTC](https://www.patreondevelopers.com/t/webhook-signature-validation-python/441 "2018-04-05T14:12:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sam](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/sam/32/492_2.png) [@sam](https://www.patreondevelopers.com/u/sam)\
**Post date:** [April 5, 2018, 4:39pm UTC](https://www.patreondevelopers.com/t/webhook-signature-validation-python/441/2 "2018-04-05T16:39:14Z")

</div>

I’ve previously posted example code for signature validation [here](https://www.patreondevelopers.com/t/webhook-signature-validation-fails/348/4) for someone else having issues – although with Javascript, not Python. Their issue was that the value they were using for the body of the request was not the actual request body, I’m going to guess the same is true here.

Looking at the documentation for [Werkzeug Request get\_data](http://werkzeug.pocoo.org/docs/0.14/wrappers/#werkzeug.wrappers.BaseRequest.get_data) I think you need to pass in `as_text=True` to obtain the right value for generating the signature.

> If as\_text is set to True the return value will be a decoded unicode string.

```auto
from hashlib import md5

secret = b'foo'
sighash = md5(secret)
sighash.update(request.get_data(as_text=True))
assert sighash.hexdigest() == request.headers['X-Patreon-Signature']

```

If this doesn’t help I’d recommend visiting the [Register Webhooks](https://www.patreon.com/portal/registration/register-webhooks) page and use one of the example webhooks body in your code instead of pulling it from the request body to verify if your signature verification is written correctly, that will help ascertain where the issue lies.

---

_[View the full topic](https://www.patreondevelopers.com/t/webhook-signature-validation-python/441)._
