title: Binance <Api-key format invalid.> with Python requests but works with curl
body: <p>I'm trying to put an order on Binance testnet using python requests. It always throws <code>{&quot;code&quot;:-2014,&quot;msg&quot;:&quot;API-key format invalid.&quot;}</code>. But the same url returns data successfully when used with curl. Can somebody please point out what's wrong with my python requests code?</p>
  <pre><code>API_KEY= &lt;api_key&gt;
  SECRET= &lt;password&gt;
  
  import time
  import requests
  import hashlib
  import hmac
  
  def hashing(query_string):
      return hmac.new(SECRET.encode('utf-8'), 
                      query_string.encode('utf-8'), 
                      hashlib.sha256).hexdigest()
  
  base_url = &quot;https://testnet.binance.vision&quot;
  api_path = &quot;/api/v3/order&quot;
  timestamp = int(time.time()*1000)
  msg = &quot;symbol=BNBUSDT&amp;side=BUY&amp;type=LIMIT&amp;quantity=1&amp;timeInForce=GTC&amp;price=200&amp;timestamp={}&quot;.format(timestamp)
  msg_hash = hashing(msg)
  
  url = f&quot;{base_url}{api_path}?{msg}&amp;signature={msg_hash}&quot;
  
  print(url)
  
  headers = {'Content-Type': 'application/json;charset=utf-8',
                      'X-MBX-APIKEY': API_KEY}
  
  print(&quot;\nusing python-requests&quot;)
  with requests.Session() as session:
      session.headers.update(headers)
      resp = session.put(url)
      print(resp)
  
  
  print(&quot;\nusing curl&quot;)
  !curl -H &quot;X-MBX-APIKEY: {API_KEY}&quot; -X POST &quot;{url}&quot;
  
  </code></pre>
  <p>colab link: <a href="https://colab.research.google.com/drive/1qPuDK_mGBchpoD4cVbq6oKvt_WY4nX71?usp=sharing" rel="nofollow noreferrer">https://colab.research.google.com/drive/1qPuDK_mGBchpoD4cVbq6oKvt_WY4nX71?usp=sharing</a></p>