Category Archives: Uncategorized

How do I send a POST request as JSON using Python?

Keep in mind you can probably accomplish this better with curl. But if you must use Python, this is absolutely the easiest way I’ve found to do this:

# import json module - will only be available for Python 2.7+
import json

# Build a json data structure:
data = {
'username' : 'admin',
'password' : 'admin',
'other' : 'blah',

# Creates the request and adding a json header
req = urllib2.Request('')
req.add_header('Content-Type', 'application/json')

# Getting the response object
response = urllib2.urlopen(req, json.dumps(data))

Remember that your will be in string format. So you may get a string output that looks like so:

{"output1":"some stuff","output2":"some more stuff"}

So that you can access say ‘output2’ variable directly, you may need to do something like:


A few extra places to read about:


Rsync tutorial: How can I keep two computers’ data synched?

You can use rsync of course. It is very simple to use.

Make sure you have it installed. On a RHEL box you can do: sudo yum install rsync or on an Ubuntu box you can do sudo apt-get install rsync. This can even be done on a Windows box but you will need to have Cygwin installed. On Windows once you have Cygwin installed you can install SSH and Rsync on it.

Next, make sure you have ssh installed. Here is how to do it with Ubuntu: link. With RHEL you can do: sudo yum install ssh.

Make sure you can ssh from the source box to the target server. If you need help doing this, see this link.

Next you can run these commands:

rsync –verbose –progress –stats –compress –rsh=/usr/local/bin/ssh \
–recursive –times –perms –links –delete \
–exclude “*bak” –exclude “*~” \
/www/* webserver:simple_path_name

  • –verbose : shows a lot of information
  • –progress : shows progress in percentage of time almost completed
  • –stats : shows amount of time taken and time sped up
  • –compress : compresses data so that it can be sent faster
  • –rsh : tells which login program you’re going to use — in our case this is ssh.
  • –recursive : tells rsync to sync up subfolder data as well
  • –times : preserves time stamp of files and folders for the new server
  • –perms : preserves permissions of files and folders for the new server
  • –links : copies over symbolic links
  • –deletes : will delete files on the target server if they do not exist on the source server
  • –exclude “[filename]” : will not sync a file/folder given here

A few other resources: