'Send a POST request and convert errors to exceptions'

def _do_post(self, uri, data=None):

    try:
        req = urllib2.Request(uri, {})
        req.add_header('Content-Type', 'application/octet-stream')
        if (data is not None):
            req.add_data(data)
        resp = json.load(urllib2.urlopen(req))
        if ('Error' in resp):
            raise ZooKeeper.Error(resp['Error'])
        return resp
    except urllib2.HTTPError as e:
        if (e.code == 201):
            return True
        elif (e.code == 409):
            raise ZooKeeper.ZNodeExists(uri)
        elif (e.code == 401):
            raise ZooKeeper.InvalidSession(uri)
        raise
