https://cerbos.dev logo
#help
Title
# help
t

Topi Hernández Mares

06/16/2022, 2:51 PM
Hi! I'm trying to add tests to my python backend using the python sdk, but I'm getting the following error:
Copy code
def is_allowed(
        self,
        action: str,
        principal: Principal,
        resource: Resource,
        request_id: Optional[str] = None,
        aux_data: Optional[AuxData] = None,
    ) -> bool:
        """Check permission for a single action
    
        Args:
            action (str): action being performed
            principal (Principal): principal who is performing the action
            resource (Resource): resource on which the action is being performed
            request_id (None|str): request ID for the request (default None)
            aux_data (None|AuxData): auxiliary data for the request
        """
        resp = self.check_resources(
            principal=principal,
            resources=ResourceList().add(resource, {action}),
            request_id=request_id,
            aux_data=aux_data,
        )
    
>       return resp.get_resource(resource.id).is_allowed(action)
E       AttributeError: 'NoneType' object has no attribute 'is_allowed'
I've been looking at the client code and I found that
get_resource
returns
None
when the request fails, but I don't know what is failing.
c

Charith (Cerbos)

06/16/2022, 2:57 PM
Interesting... there are two things you can try. • Set
raise_on_error=True
when constructing the Cerbos client. That could give you an idea by throwing an exception. • Set
debug=True
(and maybe
logger
as well) and you should be able to see the requests and responses
t

Topi Hernández Mares

06/16/2022, 2:58 PM
Thanks, I will try
c

Charith (Cerbos)

06/16/2022, 3:02 PM
You could also try printing out
resp.status_msg
.
t

Topi Hernández Mares

06/16/2022, 3:05 PM
Where can I access
resp
?
From the client?
c

Charith (Cerbos)

06/16/2022, 3:06 PM
I am referring to the variable called
resp
you have in the above example.
t

Topi Hernández Mares

06/16/2022, 3:08 PM
Ohh, that code above is from the python sdk, I will try to print it
Thanks, I found the issue!
c

Charith (Cerbos)

06/16/2022, 4:06 PM
Great! What was it?
t

Topi Hernández Mares

06/16/2022, 4:07 PM
I was getting a
400
because I wasn't sending roles in my Principal
Copy code
'{"code":3, "message":"invalid CheckResourcesRequest.Principal: embedded message failed validation | caused by: invalid Principal.Roles: value must contain at least 1 item(s)"}'}
c

Charith (Cerbos)

06/16/2022, 4:08 PM
I see. Glad you found the issue 🙂
21 Views