def test_reply_schema_default_error(self): response = self.fetch(f'/error', method='GET') data = json_decode(response.body) assert response.code == 500 assert data['msg'] == 'server error' assert data['code'] == 500000 assert 'traceback' not in data
def prepare(self, request): request.content.seek(0, 0) content = request.content.read() if content: return defer.succeed(json_decode(content)) else: return defer.succeed(None)
def prepare(self, request): request.content.seek(0, 0) content = request.content.read() log.msg("content size = %d" % len(content), level=DEBUG) if content: return defer.succeed(json_decode(content)) else: return defer.succeed(None)
def test_reply_schema_default_error_with_traceback(self): options.debug = True response = self.fetch(f'/error', method='GET') options.debug = False data = json_decode(response.body) assert response.code == 500 assert data['msg'] == 'server error' assert data['code'] == 500000 assert 'traceback' in data
async def consume(self): if not hasattr(self, 'active_queue'): raise JSONQueueError('no active queue set') msg = await self.active_queue.get() if msg.content_type != 'application/json': msg.reject(requeue=False) return None try: data = json_decode(msg.body) except ValueError as e: msg.reject(requeue=False) return None return data, msg
def prepare(self): super().prepare() content_type = self.request.headers.get('Content-Type') if not self.request.body: return if not content_type: return if content_type.strip().lower().startswith('application/json'): try: self.data = json_decode(self.request.body) except ValueError as e: raise InvalidJSONRequestData() from e
def get_postdata(self, request): request.content.seek(0, 0) content = request.content.read() try: if content: data = json_decode(content) else: data = dict() except ValueError: raise exception.MalformedIncomingData('must be json') if not isinstance(data, dict): raise exception.MalformedIncomingData('must be json dict') return data
def _prepare(self, request, content=True): node_path, format = NodeService._buildQuery(request) if content: request.content.seek(0, 0) content = request.content.read().strip() or "{}" try: data = json_decode(content) except: raise InvalidInputData("Invalid JSON") else: data = dict() return INode(node_path=node_path, format=format, data=data, user=request.getUser(), passwd=md5sum(request.getPassword()).hexdigest())
def decode(token, secret=None): def _b(s): # Pad the incoming base64 before decode return s if len(s) % 4 == 0 else s + '=' * (4 - len(s) % 4) try: enc, sign = token.split('.') iv = Random.new().read(AES.block_size) cipher = AES.new(_key(secret), AES.MODE_CBC, iv) raw = b64decode(_b(enc)) json_data = str(_unpad(cipher.decrypt(raw))[len(iv):], 'UTF-8') if str(_hmac(json_data, secret), 'UTF-8') == _b(sign): return json_decode(json_data) else: raise InvalidSecureTokenSignatureError() except InvalidSecureTokenSignatureError: raise except Exception as e: raise InvalidSecureTokenError() from e
def _http_done(self, message, user, channel): message = fix_message_encoding(json_decode(message)) if "users" not in message and "channels" not in message: message["users"], message["channels"] = \ self._default_target(user, channel) return message
def test_reply_schema_custom_error_wild(self): response = self.fetch(f'/error/custom/wild', method='GET') data = json_decode(response.body) assert response.code == 599 assert data['name'] == 'division by zero'
def test_reply_schema_custom_error(self): response = self.fetch(f'/error/custom', method='GET') data = json_decode(response.body) assert response.code == 599 assert data['name'] == 'server error'