def __build_json_body(self): if "content-type" not in self.request._headers_keys_in_lowcase.keys() or \ not self.request._headers_keys_in_lowcase["content-type"].lower().startswith("application/json"): raise HttpError( 400, 'The content type of this request must be "application/json"') return JSONBody(self.request.json)
def my_ctrl2(data=JSONBody()): predictions = predictor.predict(messages=data["messages"]) results = list(map(lambda x: True if x[0] else False, predictions)) resultsJSON = json.dumps(results) return Response(status_code=200, headers={ "Access-Control-Allow-Origin": "*", "Content-Type": "application/json", "Access-Control-Allow-Headers": "*" }, body=resultsJSON)
def your_ctroller_function(data=JSONBody(),res=Response()): getdata_response.GET_DATA = []#清空一下全局变量 userList = data.get("userList") if len(userList) > 0: for user in userList: print(user['userName']+" : "+user['identityId']) #调用抓取数据方法 getdata_response.parse_page(user['identityId'],user['userName']) time.sleep(3)#五秒 #批量插入数据调用接口: user_service.insert(None,getdata_response.GET_DATA) # res.body = json.dumps(getdata_response.GET_DATA,ensure_ascii=False) res.body = "<html><body>操作成功!</body></html>" res.send_response()
def post_json(json=JSONBody()): print(json) return json