title: Connecting to a rest API with python. How to setup headers & parameters?
body: <p>i'm working on settin up a rest api with python, however i'm having some problem getting it to work.</p>
  
  <p>I'm working with the TV DB rest api: <a href="https://api.thetvdb.com/swagger" rel="nofollow noreferrer">https://api.thetvdb.com/swagger</a></p>
  
  <p>and using python with Requests library to pull out the information.</p>
  
  <p>My code is currently: </p>
  
  <pre><code>import json 
  import requests
  
   URL = "https://api.thetvdb.com/"
  
  API_KEY = "Api_key"
  USER_KEY = "Key"
  USERNAME = "Name"
  
  headers  = {"Accept": "application/json"}
  params = {
    "apikey": API_KEY,
    "userkey": USER_KEY,
    "username": USERNAME
  }
  
  resp = requests.post(URL + "login/", headers = headers ,params=params)
  
  if resp.status_code != 200:
      print('error: ' + str(resp.status_code))
  else:
      print('Success')
  </code></pre>
  
  <p>So far i'm only getting error code 401, not sure why.</p>
  
  <p><strong>Solved:</strong></p>
  
  <p>2 Things needed to be changed
  1. The resp was changed into: </p>
  
  <pre><code>resp = requests.post(URL + "login/", headers = headers, data=json.dumps(params))
  </code></pre>
  
  <ol start="2">
  <li><p>The header had to have </p>
  
  <pre><code>"Content-Type": "application/json"
  </code></pre></li>
  </ol>
  
  <p>added to it :) It's now working, thanks everyone</p>