OiO.lk Blog python AttributeError: 'SyncRequestBuilder' object has no attribute 'on'
python

AttributeError: 'SyncRequestBuilder' object has no attribute 'on'


I get an error when configuring a listener in the supabase database using python. I chose the on().subscribe() method, but the documentation does not say exactly how to use it. I assume that I am using the method incorrectly

import os
#os.environ["KIVY_NO_CONSOLELOG"] = "1"
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label  
from kivy.uix.image import Image
from kivy.uix.textinput import TextInput
from kivy.uix.popup import Popup
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.uix.checkbox import CheckBox
from kivy.config import Config
from kivy.clock import Clock
from supabase import create_client, Client
from dotenv import load_dotenv
import requests, json
load_dotenv()
Builder.load_file("login.kv")


url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


class TVOneScreen(Screen):
    def __init__(self, **kwargs):
        super(TVOneScreen, self).__init__(**kwargs)
        supabase.from_("users").on("UPDATE", print("Внесены изменения в USERS")).subscribe()

    def on_enter(self):
        Clock.schedule_once(self.user_list)

    def user_list(self, dt):
        print("Метод создания списка рейтинга запущен")
        DB.select()
        for i in range(9):
            number_id = f'lbl_number_{i+1}'
            user_id = f'lbl_user_{i+1}'
            score_id = f'lbl_score_{i+1}' 
            self.ids[number_id].text=""       
            self.ids[user_id].text="" 
            self.ids[score_id].text=""
        for a in range(len(array)):
            number_id = f'lbl_number_{a+1}'
            user_id = f'lbl_user_{a+1}'
            score_id = f'lbl_score_{a+1}'
            self.ids[number_id].text = str(a+1)    
            self.ids[user_id].text = array[a]['name']
            self.ids[score_id].text = str(array[a]['score_r'])

class DB():

    def select():
        array.clear()
        print("Запустился select")
        try:
            response = supabase.table("users").select("*").neq('hide', '1').order('score_r', desc=True).execute()
            for r in response.data:
                array.append(r)
        except Exception as e:
            print("Произошла ошибка при вставке данных:", e)
        print("Завершился select. Количество элементов в list = " + str(len(array)))
        # print( f"Array[0]['name']= {array[0]['name']}")

class MyKivyApp(App):
    def build(self):
        sm = ScreenManager()
        sm.add_widget(TVOneScreen(name="tv_one"))
        return sm


if __name__ == '__main__':
    MyKivyApp().run()

Backtracking:

 Traceback (most recent call last):
   File "D:\kivy-lessons\lesson1\main.py", line 34, in <module>
     supabase.from_("users").on("UPDATE", print("Внесены изменения в USERS")).subscribe()
 AttributeError: 'SyncRequestBuilder' object has no attribute 'on'

The users table in the database:

When updating data in the users table, the text should be printed in the terminal: "Внесены изменения в USERS"



You need to sign in to view this answers

Exit mobile version