title: Python makes wrong hashes of dictionary
body: <p>Ran into a hashing problem:
  I’m trying to hash using HMAC-SHA1</p>
  <p>On Python 3.9 I use this code:</p>
  <pre><code>import hmac
  import json
  from hashlib import sha1
  
  secret = &quot;1b87e199bb4791db3f0920784e14c91df6c83df9&quot;
  dic = {'name':'Andrew',
         'color':'white'}
  sign = hmac.new(secret.encode('utf-8'),json.dumps(dic).encode('utf-8'),sha1).hexdigest()
  </code></pre>
  <blockquote>
  <p>83de79802d654cd6b94b6561dad1b882c918f3f5</p>
  </blockquote>
  <p>But using almost the same code on PHP I get more correct result (the result I need)</p>
  <pre><code>$dic =json_encode([
      &quot;name&quot; =&gt; &quot;Andrew&quot;,
      &quot;color&quot; =&gt; &quot;white&quot;,
  ]);
  $sig = hash_hmac('sha1', $dic, $secret);
  </code></pre>
  <blockquote>
  <p>d6b6305ebc39b44d10160c80a95f65faff0167b9</p>
  </blockquote>
  <p>My secret: <code>1b87e199bb4791db3f0920784e14c91df6c83df9</code></p>
  <p>What’s whong with my dict hashing on Python, what am I doing wrong?</p>