To avoid repeated authentication prompts on the TV, you must correctly manage the store object.
- First Run: Pass an empty dictionary
{} as the store. This triggers an authentication prompt on the TV. - Registration: Once the user completes the registration on the TV, the
store object is populated with the necessary credentials. - Persistence: You must save (persist) the contents of the
store to a database, config file, or other permanent storage. - Subsequent Runs: Load the saved data and pass it back into the client as the
store. If you pass an empty object again, the TV will prompt for re-authentication.
Pro-tip: The client.register(...) method expects an object that implements __getitem__ and __setitem__. You can create a custom class that automatically reads from and writes to your storage within these methods to automate persistence.
# Conceptual pattern for automatic persistence
# client.register expects an object with __getitem__ and __setitem__
class PersistentStore:
def __getitem__(self, key):
return load_from_disk(key)
def __setitem__(self, key, value):
save_to_disk(key, value)