Title
#help
Topi Hernández Mares

Topi Hernández Mares

06/22/2022, 2:33 PM
Hello again! I'm having a weird behavior with the Python SDK, let me try to explain it here. I'm getting the following error, but only in a specific scenario:
RuntimeError("Cannot send a request, as the client has been closed.")
This only happens when I make two or more requests to Cerbos with the SDK
2:35 PM
I have the following code:
for id in profile_skills_ids:
    profile_skill = self.update(id=id, level=level)
And inside
update
I have the
client.is_allowed...
for checking the auth with Cerbos
Charith (Cerbos)

Charith (Cerbos)

06/22/2022, 2:51 PM
That's strange. The internal client should only be closed when the context manager exits (or when
close()
is called)
2:52 PM
Let me try this out
2:53 PM
Oh wait..this is not just a simple loop. Can you please show how the Cerbos client is used inside the
update
method?
Topi Hernández Mares

Topi Hernández Mares

06/22/2022, 2:58 PM
2:59 PM
Charith (Cerbos)

Charith (Cerbos)

06/22/2022, 3:00 PM
Ah! The issue is that you're using the global Cerbos client within a context manager (
with self._cerbos_client
). So, after the first call to
update
the client gets closed and no longer usable
3:01 PM
Remove the
with
and it should work
Topi Hernández Mares

Topi Hernández Mares

06/22/2022, 3:01 PM
Oh! Let me try
3:03 PM
Thanks, now it works!
Charith (Cerbos)

Charith (Cerbos)

06/22/2022, 3:03 PM
Yay!