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
Answers:
I solved it by changing the database key to not just be the user.
Replit Database doesn’t support integers as keys. Stringify the key beforehand.
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
I solved it by changing the database key to not just be the user.
Replit Database doesn’t support integers as keys. Stringify the key beforehand.