Пример #1
0
    def callMethod(self, svcname, param):
        postobj = {
                'nsp_fmt': 'php-rpc',
                'nsp_svc': svcname,
                'nsp_app': self.appid,
                'nsp_ts': int(time.time()),
                'nsp_params': dumps(param)
                }
        if len(str(self.appid))>32:
            postobj.pop('nsp_app')
            postobj['nsp_sid']  = self.appid

        postobj['nsp_key'] = self.signRequest(postobj)

        postdata = urllib.urlencode([(k, isinstance(postobj[k], unicode) and postobj[k].encode('utf-8') or postobj[k]) for k in postobj.keys()])
        o = self._urlopener.open(self.nspUrl, postdata)
        respdata = o.read()
        httpStatus = o.info().getheader('Status')
        nspStatus = o.info().getheader('NSP_STATUS')
        if httpStatus=='200' or httpStatus == None:
            if nspStatus == None:
                return loads(respdata)
            else:
                raise Exception(loads(respdata))
        else:
            raise NSPException(loads(respdata))
Пример #2
0
 def http_error_default(self, url, fp, errcode, errmsg, headers):
     data = fp.read()
     fp.close()
     if errcode == 406:
         raise NSPException(loads(data))
     else:
         raise NSPException('HTTP Error: %s' % errmsg)