# HMAC mismatch Issue

**URL:** <https://community.hubspot.com/t/hmac-mismatch-issue/59583>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [June 22, 2022, 5:33pm UTC](https://community.hubspot.com/t/hmac-mismatch-issue/59583 "2022-06-22T17:33:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BCoons1](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@BCoons1](https://community.hubspot.com/u/BCoons1)\
**Post date:** [June 22, 2022, 5:33pm UTC](https://community.hubspot.com/t/hmac-mismatch-issue/59583/1 "2022-06-22T17:33:36Z")

</div>

I am trying to verify the hmac in the

X-HubSpot-Signature V2 but we cannot seem to get a match. I have tried encoding the uri, decoding, encoding just the query string, encoding but with & and = safe, with query string, without, and I don’t even know how many other things. We are receiving a GET request so there is no request body but I have tried including request.json, request.data etc just for funsies. I verified the secret from env\_vars does match the secret in my app. I followed the given python example and my code is below:

prehash\_string = env\_vars[‘hubspot\_crm\_card\_secret’] + request.method + request.url

hashed\_string = hashlib.sha256(prehash\_string.encode(‘utf-8’)).hexdigest()

print(f’{hashed\_string} == {hubspot\_signature}')

if hashed\_string == hubspot\_signature:

print(‘authorized’)

return True

return False

Any idea what I am missing here?

---

<div class="post-metadata">

**Author:** ![BCoons1](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@BCoons1](https://community.hubspot.com/u/BCoons1)\
**Post date:** [June 22, 2022, 6:01pm UTC](https://community.hubspot.com/t/hmac-mismatch-issue/59583/2 "2022-06-22T18:01:35Z")

</div>

In case someone else has this issue, I solved it by adding:

url = urllib.parse.unquote(request.url).replace(‘http’, ‘https’, 1)

For some reason request.url came through as http but the hmac had https and the @'s in the query were encodded but nothing else was. I only replaced the first http because my query included the domains
