title: Calculate hmac value with base64 encode using sha256 python
body: <p>I'm trying to transform a php code into python language.</p>
  
  <p>the php function calculates the hmac value using sha256 and base64 encoding.</p>
  
  <p><strong>My Php function:</strong></p>
  
  <pre><code>&lt;?php
  
  define('SHOPIFY_APP_SECRET', 'some_key');
  
  function verify_webhook($data)
  {
  $calculated_hmac = base64_encode(hash_hmac('sha256', $data, 
  SHOPIFY_APP_SECRET, true));
  echo $calculated_hmac;
  }
  
  $data = "some_data";
  $verified = verify_webhook($data);
  ?&gt;
  </code></pre>
  
  <p><strong>My Python function:</strong></p>
  
  <pre><code>import base64
  import hmac
  import binascii
  from hashlib import sha256
  
  API_SECRET_KEY = "some_key"
  data = "some_data"
  
  def verify_webhook():
      dig = hmac.new(
          API_SECRET_KEY,
          msg=data,
          digestmod=sha256
          ).digest()
      calculated_hmac = base64.b64encode(bytes(binascii.hexlify(dig)))
      print(calculated_hmac)
  
  verify_webhook()
  </code></pre>
  
  <p>I got different outputs even I have the same key and data. I still don't know what I'm missing here. please help!</p>
  
  <p><strong>Python output:</strong></p>
  
  <blockquote>
    <p>YWM3NjlhMDZjMmViMzdmM2E3YjhiZGY4NjhkNTZhOGZhMDgzZDM4MGM1OTkyZTM4YjA5MDNkMDEwNGEwMzJjMA==</p>
  </blockquote>
  
  <p><strong>Php output:</strong></p>
  
  <blockquote>
    <p>N7JyAyKocoDx/Opx36nGqAuUKdyGH+ROX+J5AJgQ+/g=</p>
  </blockquote>