def identify_request ( request : RequestType ) -> bool : # noinspection PyBroadException try : data = json . loads ( decode_if_bytes ( request . body ) ) if "@context" in data : return True except Exception : pass return False
how to check if a request is valid or not in python
Try to identify whether this is an ActivityPub request .
def identify_request(request: RequestType) -> bool:
    """
    Try to identify whether this is an ActivityPub request.
    """
    # noinspection PyBroadException
    try:
        data = json.loads(decode_if_bytes(request.body))
        if "@context" in data:
            return True
    except Exception:
        pass
    return False