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

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:
Copy code
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
I have the following code:
Copy 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
c

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)
Let me try this out
Oh wait..this is not just a simple loop. Can you please show how the Cerbos client is used inside the
update
method?
t

Topi Hernández Mares

06/22/2022, 2:58 PM
c

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
Remove the
with
and it should work
t

Topi Hernández Mares

06/22/2022, 3:01 PM
Oh! Let me try
Thanks, now it works!
🎉 1
c

Charith (Cerbos)

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