You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Token request that specifies capabilities:
capabilities = {
"chat:bob": ["subscribe"], # only "subscribe" intersects
"status": ["*"], # "*" intersects with "subscribe"
"secret": ["publish", "subscribe"] # key does not have access to "secret" channel
}
token_details = await ably_rest.auth.request_token({
'capability': json.dumps(capabilities)
})
Will result in the following error:
File "/usr/local/lib/python3.12/site-packages/ably/rest/auth.py", line 272, in create_token_request
token_request['capability'] = str(Capability(capability))
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/ably/types/capability.py", line 13, in __init__
self.__dict = dict(obj)
^^^^^^^^^
ValueError: dictionary update sequence element #0 has length 1; 2 is required
This is due to the following init form Capability:
class Capability(MutableMapping):
def __init__(self, obj=None):
if obj is None:
obj = {}
self.__dict = dict(obj)
for k, v in obj.items():
self[k] = v
Unwrapping capabilities from the suggested json.dumps() solves the issue
The SDK is intended to be able to accept a JSON string for the capability parameter (as well as a dictionary) when creating token details. The fact that it cannot process json.dumps(capabilities) is a bug. We will fix this in the library.
In the meantime, you can pass a dictionary directly when creating a token, just as you suggested:
Following the tutorial at https://ably.com/docs/auth/capabilities:
Will result in the following error:
This is due to the following init form
Capability
:Unwrapping
capabilities
from the suggestedjson.dumps()
solves the issue┆Issue is synchronized with this Jira Task by Unito
The text was updated successfully, but these errors were encountered: