title: hash_hmac sha512 authentication in python
body: <p>I'm trying to write python authentication bot for: <a href="https://comkort.com/page/private_api" rel="nofollow noreferrer">https://comkort.com/page/private_api</a></p>
  
  <p>There is no full php example. I'm guess somebody could put it here.</p>
  
  <p>There is only snippet of php code:</p>
  
  <pre><code>$query_string = http_build_query($_POST, '', '&amp;');
  $ethalon_sign = hash_hmac("sha512", $query_string, $api_secret_key);
  </code></pre>
  
  <p>How to write authentication on python with hash_hmac sha512 ?</p>
  
  <p>I want to extract my <code>open orders</code> <code>POST https://api.comkort.com/v1/private/order/list</code>.</p>
  
  <p>My current variant is:</p>
  
  <pre><code>import hashlib
  import hmac
  import requests
  import time
  
  privateKey = b'myprivatekey'
  publicKey = 'my public key'
  
  url = 'https://api.comkort.com/v1/private/order/list'
  tosign = b'market_alias=doge_ltc'
  signing = hmac.new( privateKey , tosign, hashlib.sha512 )
  headers = {'sign': signing.digest(), "apikey": publicKey, "nonce": int( time.time() ) }
  
  r = requests.get(url, headers=headers)
  print r.text
  </code></pre>
  
  <p>I'm caught this</p>
  
  <pre><code>{"code":401,"error":"Invalid sign","field":"sign"}
  </code></pre>
  
  <p>May be hexdigest() instead digest()? I don't know, I'm playing around this <code>b</code> prefix and different output hmac's options, everytime I'm caught one error: "Invalid sign".</p>
  
  <p>Related: <a href="https://stackoverflow.com/questions/24429307/hmac-signing-requests-in-python">HMAC signing requests in Python</a></p>