title: Testing a RESTful API with POSTs from Python
body: <p>I'm trying to test a RESTful interface I'm working on (I'm using this one: <a href="http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/" rel="nofollow noreferrer">codeigniter-restserver</a>), and I'd like to use Python.</p>
  
  <p><code>GET</code>s seem to be working okay, but I'm having trouble with <code>POST</code>s. I'm not asking about the ins &amp; outs of this library, rather I'm just trying
  to figure out how to test <code>POST</code>ing with Python. This is what I've got:</p>
  
  <pre><code>import httplib, urllib
  
  params = urllib.urlencode({
      'sentence':     'esta es una frase',
      'translation':  'this is a sentence'
  })
  
  headers = {
      "Content-type": "application/x-www-form-urlencoded", 
      "Accept":       "text/plain"
  }
  
  conn = httplib.HTTPConnection("localhost:80")
  conn.request("POST", "/myapp/phrase", params, headers)
  
  response = conn.getresponse()
  print response.status, response.reason
  
  data = response.read()
  conn.close()
  </code></pre>
  
  <p>Is this script sufficient as a way to test <code>POST</code>ing? I've seen a lot of requests on SO about people looking for GUI tools to do this (Firefox plugins, <a href="https://stackoverflow.com/questions/2435838/gui-http-client">etc</a>)
  but for me the whole point of building a RESTful app in the first place is to have an API I can script to to modify the db quickly. (Populate it with data
  from a JSON file, whatever.)</p>
  
  <p>Am I on the right track with this Python-based approach?</p>
  
  <p>Thanks</p>