'Sends an RPC and returns the response.
Args:
request_path: The path to send the request to, eg /api/appversion/create.
payload: The body of the request, or None to send an empty request.
content_type: The Content-Type header to use.
timeout: timeout in seconds; default None i.e. no timeout.
(Note: for large requests on OS X, the timeout doesn\'t work right.)
kwargs: Any keyword arguments are converted into query string parameters.
Returns:
The response body, as a string.'

def Send(self, request_path, payload='', content_type='application/octet-stream', timeout=None, **kwargs):

    old_timeout = socket.getdefaulttimeout()
    socket.setdefaulttimeout(timeout)
    try:
        tries = 0
        auth_tried = False
        while True:
            tries += 1
            url = ('%s://%s%s' % (self.scheme, self.host, request_path))
            if kwargs:
                url += ('?' + urllib.urlencode(sorted(kwargs.items())))
            req = self._CreateRequest(url=url, data=payload)
            req.add_header('Content-Type', content_type)
            req.add_header('X-appcfg-api-version', '1')
            try:
                logger.debug('Sending    %s    request:\n%s', self.scheme.upper(), HttpRequestToString(req, include_data=self.debug_data))
                f = self.opener.open(req)
                response = f.read()
                f.close()
                return response
            except urllib2.HTTPError as e:
                logger.debug('Got    http    error,    this    is    try    #%s', tries)
                if (tries > self.rpc_tries):
                    raise
                elif (e.code == 401):
                    if auth_tried:
                        raise
                    auth_tried = True
                    self._Authenticate()
                elif ((e.code >= 500) and (e.code < 600)):
                    continue
                elif (e.code == 302):
                    if auth_tried:
                        raise
                    auth_tried = True
                    loc = e.info()['location']
                    logger.debug('Got    302    redirect.    Location:    %s', loc)
                    if loc.startswith('https://www.google.com/accounts/ServiceLogin'):
                        self._Authenticate()
                    elif re.match('https://www\\.google\\.com/a/[a-z0-9\\.\\-]+/ServiceLogin', loc):
                        self.account_type = os.getenv('APPENGINE_RPC_HOSTED_LOGIN_TYPE', 'HOSTED')
                        self._Authenticate()
                    elif loc.startswith(('http://%s/_ah/login' % (self.host,))):
                        self._DevAppServerAuthenticate()
                    else:
                        raise
                else:
                    raise
    finally:
        socket.setdefaulttimeout(old_timeout)
