title: Getting eBay Access Token (Exchanging auth token) with python requests
body: <p>I'm trying to use <a href="https://developer.ebay.com/devzone/rest/ebay-rest/content/oauth-gen-user-token.html" rel="noreferrer">this guide</a> to get access token.</p>
  
  <p>Here is my main file:</p>
  
  <pre><code>import requests
  
  from utils import make_basic_auth_header, conf
  code = '&lt;Auth code here&gt;'
  url = "%s/identity/v1/oauth2/token" % conf('EBAY_API_PREFIX')
  headers = {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Authorization': make_basic_auth_header()
      }
  
  data = {
      'grant_type': 'authorization_code',
      # 'grant_type': 'refresh_token',
      'state': None,
      'code': code,
      'redirect_uri': conf('EBAY_RUNAME')
  }
  r = requests.post(
      url,
      data=data,
      headers=headers,
  )
  </code></pre>
  
  <p>Here's the <code>make_basic_auth_header()</code> function:</p>
  
  <pre><code>def make_basic_auth_header():
      auth_header_payload = '%s:%s' % (conf('EBAY_APP_ID'), conf('EBAY_CERT_ID'))
      auth_header_base64 = base64.b64encode(auth_header_payload)
      auth_header = 'Basic %s' % auth_header_base64
      return auth_header
  </code></pre>
  
  <p>But all I get in <code>r.json()</code> is:</p>
  
  <pre><code>{u'error_description': u'request is missing a required parameter or malformed.', u'error': u'invalid_request'}
  </code></pre>
  
  <p>I'm frustrated - what am I doing wrong?</p>