Hey everyone! I wanted some help with the firebase module.......could someone help me? btw am a noob

As said in the title, I am having some problems with firebase’s firebase.put() function.
here’s the code:

from tkinter import *
from firebase import firebase
from simplecrypt import encrypt, decrypt

login_window = Tk()
login_window.geometry("400x400")
login_window.config(bg='#AB92BF')

fbase = firebase.FirebaseApplication("https://chattap-335d8-default-rtdb.firebaseio.com/", None)
print("firebase done")


login_window = Tk()
login_window.geometry("400x400")
login_window.config(bg='#AB92BF')

username = ''
your_code = ''
your_friends_code = ''
message_text = ''
message_entry = ''
last_value = ''

def getData():
    global message_text 
    global last_value
    global your_code
    global your_friends_code
    get_your_data = firebase.get('/', your_code)
    print(get_your_data)
    byte_str = bytes.fromhex(get_your_data)
    original = decrypt('AIM', byte_str)
    print(original)
    final_message = original.decode("utf-8")
    print(final_message)
    message_text.insert(END, final_message+"\n")
    
    get_friends_data = firebase.get('/', your_friends_code)
    if (get_friends_data() != None):
        print(get_friends_data)
        byte_str = bytes.fromhex(get_friends_data)
        original = decrypt('AIM', byte_str)
        print(original)
        final_message = original.decode("utf-8")
        if (final_message != NONE):
            print(final_message)
            message_text.insert(END, final_message+"\n")
            last_value = final_message
        
    
def sendData(): 
    global username
    global message_entry
    global your_code
    message = username+ " : " + message_entry.get()
    ciphercode = encrypt('AIM', message)
    hex_string = ciphercode.hex()
    put_date = firebase.put("/", your_code, hex_string)
    print(put_date)
    getData()

def enterRoom():
    global message_entry
    
    message_window = Tk()
    message_window.config(bg='#AFC1D6')
    message_window.geometry("600x500")
    
    message_text = Text(message_window, height=20, width=72)
    message_text.place(relx=0.5,rely=0.35, anchor=CENTER)
    
    message_label = Label(message_window, text="Message " , font = 'arial 13', bg='#AFC1D6', fg="white")
    message_label.place(relx=0.3,rely=0.8, anchor=CENTER)
    
    message_entry = Entry(message_window, font = 'arial 15')
    message_entry.place(relx=0.6,rely=0.8, anchor=CENTER)
    
    btn_send = Button(message_window, text="Send", font = 'arial 13', bg="#D6CA98", fg="black", padx=10, relief=FLAT, command=sendData)
    btn_send.place(relx=0.5,rely=0.9, anchor=CENTER)
    
    message_window.mainloop()
    login_window.destroy()
    

username_label = Label(login_window, text="Username : " , font = 'arial 13', bg ='#AB92BF', fg="white")
username_label.place(relx=0.3,rely=0.3, anchor=CENTER)

username_entry = Entry(login_window)
username_entry.place(relx=0.6,rely=0.3, anchor=CENTER)

your_code_label = Label(login_window, text="Your code :  " , font = 'arial 13', bg ='#AB92BF', fg="white")
your_code_label.place(relx=0.3,rely=0.4, anchor=CENTER)

your_code_entry = Entry(login_window)
your_code_entry.place(relx=0.6,rely=0.4, anchor=CENTER)

friends_code_label = Label(login_window, text="Your Friends code :  " , font = 'arial 13', bg ='#AB92BF', fg="white")
friends_code_label.place(relx=0.22,rely=0.5, anchor=CENTER)

friends_code_entry = Entry(login_window)
friends_code_entry.place(relx=0.6,rely=0.5, anchor=CENTER)

btn_start = Button(login_window, text="Start" , font = 'arial 13' , bg="#CEF9F2", fg="black", command=enterRoom, relief=FLAT, padx=10)
btn_start.place(relx=0.5,rely=0.65, anchor=CENTER)

login_window.mainloop()

and here’s the error i get on cliking the “send” button"

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "filepath", line 58, in sendData
    put_date = firebase.put("/", your_code, hex_string)
AttributeError: module 'firebase.firebase' has no attribute 'put'

also getting the same error on clicking the “sign up” button in the following code:

import hashlib as h
from tkinter import *
from firebase import firebase

registration_window = Tk()
registration_window.geometry("400x400")
firebase.FirebaseApplication("https://project-mk1-default-rtdb.firebaseio.com/", None)

login_username_entry = ""
login_password_entry = ""

def login(): 
    print("login function")
    
def register(): 
    username = username_entry.get()
    password = password_entry.get()
    encpswrd = h.md5(password.encode())
    hex_string = encpswrd.hexdigest()
    print(username)
    print(password)
    print(encpswrd)
    print(hex_string)
    put_date = firebase.put("/", username, hex_string)
    
def login_window():
    global login_username_entry
    global login_password_entry
    
    registration_window.destroy()
    
    login_window = Tk()
    login_window.geometry("400x400")
    
    log_heading_label = Label(login_window, text="Log In" , font = 'arial 18 bold')
    log_heading_label.place(relx=0.5,rely=0.2, anchor=CENTER)
    
    login_username_label = Label(login_window, text="Username : " , font = 'arial 13')
    login_username_label.place(relx=0.3,rely=0.4, anchor=CENTER)
    
    login_username_entry = Entry(login_window)
    login_username_entry.place(relx=0.6,rely=0.4, anchor=CENTER)
    
    login_password_label = Label(login_window, text="Password : " , font = 'arial 13')
    login_password_label.place(relx=0.3,rely=0.5, anchor=CENTER)
    
    login_password_entry = Entry(login_window)
    login_password_entry.place(relx=0.6,rely=0.5, anchor=CENTER)
    
    btn_login = Button(login_window, text="Log In" , font = 'arial 13 bold' , command=login, relief=FLAT)
    btn_login.place(relx=0.5,rely=0.65, anchor=CENTER)
    
    login_window.mainloop()
    
    
heading_label = Label(registration_window, text="Register" , font = 'arial 18 bold')
heading_label.place(relx=0.5,rely=0.2, anchor=CENTER)

username_label = Label(registration_window, text="Username : " , font = 'arial 13')
username_label.place(relx=0.3,rely=0.4, anchor=CENTER)

username_entry = Entry(registration_window)
username_entry.place(relx=0.6,rely=0.4, anchor=CENTER)

password_label = Label(registration_window, text="Password :  " , font = 'arial 13')
password_label.place(relx=0.3,rely=0.5, anchor=CENTER)

password_entry = Entry(registration_window)
password_entry.place(relx=0.6,rely=0.5, anchor=CENTER)

btn_reg = Button(registration_window, text="Sign Up" , font = 'arial 13 bold' ,command=register, relief=FLAT, padx=10)
btn_reg.place(relx=0.5,rely=0.75, anchor=CENTER)

btn_login_window = Button(registration_window, text="Log In" , font = 'arial 10 bold' ,  command=login_window, relief=FLAT)

btn_login_window.place(relx=0.9,rely=0.06, anchor=CENTER)
registration_window.mainloop()

all help’s appreciated :D. Thanks!

Thank you for including your full code and error message in proper code blocks. This makes it much easier for us to figure out what’s going on.

In general, it is usually a good idea to ask questions about specific libraries, like firebase, in forums specific to said libraries, as this is the Discourse for the Python language itself. You’ll both generally get better help, and be better received by the community. In any case, I can guess at what is going on, but I would likely know right away if I was a user of this package (which I’ve never seen before).

Also, which likely helped contribute both to your problem, and to the difficulty for us in figuring out what was going on, is some of the bad practices in the above code that leave the global namespace rather polluted and hard to follow and reason about.

In particular, you should never, ever use from spam import * in any serious code, as it sticks all the names from the module into your global namespace. This means any arbitrary name might or might not be defined in said module, and is difficult if not impossible for either humans or linting/completion/introspection/help tooling to reason this out.

Furthermore, the code makes very heavy use of global for no clear reason, and functions don’t return values but rather set variables in the global namespace, which is extremely hard to follow and reason about, since anything anywhere can set any variable rather than there being a clear flow of inputs to and outputs from functions. For GUI programming like this, you likely want to consider an object-oriented programming style, which Python is equally well-suited for, if you don’t want to pass around and keep track of lots of individual variables, and structure your logic in a more appropriate pattern.

In any case, unless the issue is that you mean to call methods on the firebase package rather than the firebase module, my guess is that you mean to be calling the methods of the fbase object you created, not the firebase.firebase module. You don’t appear to use that object anywhere in your code, and in fact don’t even assign it to a name in the second example, so I’m guessing you mean to be calling, e.g. fbase.put() instead of firebase.firebase.put(). If that’s not it, then I suggest re-reading the API docs for firebase, giving your code a clearer structure and debugging accordingly.

Best of luck!

Thanks. I used the from spam import * and the usage of the global function as this is a project that I have been assigned. Anyway, I’ll try that and get back to you.

Thanks for the help. It’s working for the second code (login one) but the first code (chattap) gives me the following error on pressing “send”

Output from spyder call 'get_namespace_view':
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "filepath to python code", line 58, in sendData
    fbase.put("/", your_code, hex_string)
  File "\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\firebase\decorators.py", line 20, in wrapped
    return f(*args, **kwargs)
  File \AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\firebase\firebase.py", line 295, in put
    assert name, 'Snapshot name must be specified'
AssertionError: Snapshot name must be specified

I see. Just keep in mind that these individual choices, as well as the overall design, are considered very bad practices and can lead to a whole host of difficult to diagnose and solve issues.

Again, if I knew anything about Firebase, I might have a more specific suggestion, but this is not really the forum for that. It looks like the arguments you’re passing to the put() method, or your_code, is not what it expects; either an argument is missing, or the value is wrong. I suggest reading the firebase API docs for this method (presumably the name parameter?) to ensure you’re calling it correctly. If you still can’t figure it out, I suggest asking on a Firebase-specific forum/help site instead, since the issue is specific to the Firebase package and this site is for the Python language itself.