Skip to content
Error when accessing replit database in python
Profile icon
ZoutigeWolf

Whenever i try to access my database with value = db["key"] I get the error TypeError: unexpected type "float".

This never happened before, can someone tell me what this means?

the file with problems = cogs/xp.py

You are viewing a single comment. View All
Profile icon
Coder100

your repl is private so we can't see your code.

Profile icon
ZoutigeWolf

@Coder100
thx for letting me know, i set it to public

Profile icon
Coder100

i see, what are you exactly trying to do here?

image

@ZoutigeWolf

the types are already correct, and no type will ever need to be converted. Also, these values don't appear to be valid dict values.

Profile icon
ZoutigeWolf

@Coder100
same error happens when i don't do the dict() it was just a test i forgot to remove

Profile icon
Coder100

what line?

@ZoutigeWolf

Profile icon
ZoutigeWolf

@Coder100
any line where i want to get a value from the database
example: xpDB = db["xp"]

Profile icon
Coder100

well i mean you put the dict function on all of them so you should remove that

@ZoutigeWolf

Profile icon
ZoutigeWolf

@Coder100
I did and it still errors

Profile icon
Coder100

@ZoutigeWolf

image

no you haven't?

Profile icon
ZoutigeWolf

@Coder100
for me it shows multiDB = db["xpMulti"]
Screenshot_1

Profile icon
Coder100

strange maybe the file didn't save

@ZoutigeWolf

Profile icon
ZoutigeWolf

@Coder100
I found the solution, apparently a dict in the database can't have a float as a value.
The xp is normally an int but the multiplier made it a float so i now round that to an int.
And I now store the multipliers as a string which i can later convert back to a float

Profile icon
xfinnbar

@ZoutigeWolf
Replit DB is based on JSON and it doesn't support anything other than strings as keys.

Profile icon
ZoutigeWolf

@xfinnbar
ohhhhhhh that makes a lot of things clear.
but when i stored info on my own pc in JSON for a project I was able to store integers and floats

Profile icon
xfinnbar

@ZoutigeWolf
They were converted to strings tho.

Profile icon
Coder100

no that's ridiculous json can have numbers as the key

however, dicts cannot.

@xfinnbar

Profile icon
Coder100

nice solution
yeah I thought the python db would get all these nitty types down for you, but I guess not

@ZoutigeWolf

Profile icon
ZoutigeWolf

@xfinnbar
i had keys as strings and values as floats / ints in my json, they werent converted

Profile icon
Coder100

in json, floats and ints are indistinguishable and everything is a float

@ZoutigeWolf