Keys stuck in Replit DB, can't delete

Hey, I was experimenting with using Replit DB and tried inserting some values using URLs as the keys. I quickly found out that having “/” in a key doesn’t work well in Replit. However, now I can’t seem to remove those faulty keys from my DB. Using python’s replit.db.clear() removes all keys except those with / and just silently fails on those. Trying to iterate through all keys causes a KeyError on the offending keys.

Anyone have any ideas for how I can remove those keys? I’m totally fine with nuking the whole DB and starting from scratch but I can’t find a way to do that which successfully removes all the faulty keys.


Try and send a DELETE request to your DB url w/ the key, you can do something like this:

import requests
import urllib
import os

db_url = os.environ["REPLIT_DB_URL"]
key = ""

resp = requests.delete(f"{db_url}/{urllib.parse.quote(key)}")

Having / in a key messes up the DB because it confuses the url api. But often delete gives and error but works.
Try the above or write a empty in it.


The way the database works, values are accessed by <db url>/key. Because of this, you might need to make sure the key is encoded correctly so that this works. Try using urllib.parse(key) on each key and see if that works.

That doesn’t seem to work, I think because the quote encoding no longer matches the faulty key in the DB

1 Like

Yeah that works now for new keys, but I still don’t have a way to remove the old erroneous keys in the DB

You might actually need to create a new Repl because you might not actually be able to change or delete those keys once set. I’m assuming you’ve tried something like this:

for key in db:

If that doesn’t work (and I haven’t used ReplDB with Python before, I mainly use NodeJS, so that snippet might be incorrect), you will probably need to create a new Repl.

Damn I was hoping that wouldn’t be the case but you might be right :frowning:

1 Like

maybe try:

from replit import db

for _x in db.keys():
     del db[_x]

basically since they send it to a server via url prefixes, some “keys” are going to be funky lol

Just delete the DB URL and make a new one.

1 Like