python replit database throwing typeError

Question:

I was trying to make functions to save, get, and get all for the Replit Python database. It doesn’t work and I can’t find out why.

Get all function:

def loadAll(user):
    if user in db.keys():
        return db[user]
    if user not in db.keys():
        db[user] = {}
        return db[user]

It throws an error at return db[user].

This is the code that fires the function (I’m using the discord.py commands extension.):

@bot.command(name = "getMyData")
async def getUserData(ctx):
    await ctx.send(ctx.author)
    await ctx.send(loadAll(ctx.author))

The error message says:
TypeError: quote_from_bytes() expected bytes

Asked By: hydro

||

Answers:

I solved it by changing the database key to not just be the user.

Answered By: hydro

Replit Database doesn’t support integers as keys. Stringify the key beforehand.

Answered By: Jodo
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.