Beispiel #1
0
 def getUsrPluginSet(self):
     try:
         url = kkbConfig.configUrl + '&mac=' + str(self.mac) + '&ip=' + str(self.ip) + '&t=' + self.os_type
         res = urllib2.urlopen(url)
         redata = res.read()
         res.close()
         redata = kkbLib.decode(redata, kkbConfig.kkbDataKey)
         return json.loads(redata)
     except Exception:
         kkbLib.error(traceback.format_exc())
Beispiel #2
0
    def postData(self):
        try:
            reData = {}
            for taskId in self.objList:
                obj = self.objList[taskId + '']
                reData[taskId + ''] = obj.returnData()
                obj.clearData()
            try:
                reData = json.dumps(reData, ensure_ascii=False)
            except Exception:
                try:
                    reData = str(reData)
                    reData = reData.encode('UTF8', errors="ignore")
                    reData = reData.decode('UTF8', errors="ignore")
                    reData = dict(eval(reData))
                    reData = json.dumps(reData, ensure_ascii=False)
                except Exception:
                    kkbLib.error('json.dumps loss!')
                    kkbLib.error(traceback.format_exc())
                    reData = {}
                    reData = json.dumps(reData, ensure_ascii=False)

            if zlib:
                reData = reData.encode('UTF8')
                reData = zlib.compress(reData, 9)
                if base64:
                    reData = base64.encodestring(reData)
                else:
                    reData = reData.encode('base64')

            parms = {'data': reData, 'post_time': self.post_time}
            parms = parse.urlencode(parms)
            parms = parms.encode('UTF8')
            command = ''
            url = kkbConfig.postUrl + '&mac=' + str(self.mac) + '&ip=' + str(self.ip)
            try:
                res = urllib2.urlopen(urllib2.Request(url, parms))
                command = res.read()
                res.close()
            except Exception:
                kkbLib.error(traceback.format_exc())
                res = urllib2.urlopen(urllib2.Request(url, parms))
                command = res.read()
                res.close()
            command = kkbLib.decode(command, kkbConfig.kkbDataKey)
            command = json.loads(command)
            if command == '':
                kkbLib.error('command is none!!')
                return ''
            return command
        except Exception:
            kkbLib.error(traceback.format_exc())