def upload(self, url, data): import json data = json.dumps(data) ip = Http.get("http://ip.6655.com/ip.aspx", datas={}, heads={'content-type': 'application/json'}) ip = ip.text headers = { 'content-type': 'application/json', 'ip': '%s' % (ip), 'Authorization': '258JWTAUTH %s' % (self.get_token()) } try: import json data = Http.post( 'http://%s:%s/%s' % (self.config()['domain'], self.config()['port'], url), data, headers) print "dfds" print data.text data = json.loads(data.text) print data if data['code'] == 400: return "上报数据失败" return True except Exception, e: print e return False
def login(self): from http import Http import json data = {'username': self.username, 'password': self.password} headers = {'content-type': 'application/json'} try: data = Http.post( 'http://%s:%s/api/token/' % (self.config()['domain'], self.config()['port']), data, headers) if data.status_code == 400: return False data = json.loads(data.text) return data['token'] except Exception, e: return False