title: Python POST JSON - Is a web framework required?
body: <p>Im a bit new to python and trying to understand a simple JSON POST example (I am using AngularJS).  I have read other Q's on SO and I see most folks use some type of framework (ie, cherrypy). </p>
  
  <p>I am able to send data (strings) via POST and upon .success, display it in a simple alert.  But only if I wrap the strings in html tags in the python code itself.  However, when I take the HTML tags out of the python script and try to return a JSON object, I get a 500 server error.  So my gut is telling me, I must use a web framework?</p>
  
  <p>Code for the failing JSON attempt.</p>
  
  <p>JS:</p>
  
  <pre><code>tableModule.factory('Service', ['$http',
  function($http) {
      return {
          post : function($path, $data, callback) {
              return $http.post($path, $data,{ headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'} }  ).success(callback);
          }
  
  ...
  Service.post('test.cgi', $.param($data), function(data, status){...
  </code></pre>
  
  <p>And the python is very simple:</p>
  
  <pre><code>import cgi
  import cgitb
  import sys
  import traceback
  import json
  
  cgitb.enable()
  
  def getData1():
  
      ...generate json data...
  
      json_string = json.dumps(dictResult)
      return json_string
  
  if __name__ == "__main__":
      try:
          #htmlTop() &lt;-- code not shown, when I wrap the python in html, i can return simple strings
          getData1()
          #htmlBottom()
      except:
          cgi.print_exception()
  </code></pre>
  
  <p>Is there a way to get this simple example working without installing a framework?</p>