there is obviously a lot more code but the piece of code below is what I’m having trouble with.
url = "https://google.com/"
db[url] = ""
# above creates a key in my replit database
# key name: "https://google.com"
# key value: ""
but when i do:
it doesn’t work and I’ve tried googling and looking at forums here but gotten no answer that solves my problem.
if you know about how to do this please help.
gives this error code below:
Traceback (most recent cal last):
File "main.py", line 53, in <module>
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/replit/database/database.py", line 540, in __delitem__ raise KeyError(key)
Welcome to the community, @Kaleb1583!
That’s an interesting bug. Can you go to
Database and check that the keys are actually being saved?
I have given it a try and from what I have seen, when the symbol / or // is used, the key/pair is created but it throws an error when trying to read it.
Looks like a bug and I would say in the meantime just replace the symbol with something else and put the symbol back when needed.
Basically replit db deletes by sending url requests to a
https://kv.replit.com/v0/... url by sending it via url key like this (code snippet from source code):
self.sess.delete(self.db_url + "/" + urllib.parse.quote(key))
I believe it is not “proper” url protocol to put '//` in it or something so basically that’s why it works for getting/setting but not deleting (replit db doesn’t do this for get/set, only for deleting for some reason).
Getting also does nit seem to work. It only works for setting.
I understanding if the issue would come with \\ as backslash is a special character, but normal slash should be ok.
Welcome to the community @Kaleb1583 , If you’re only saving URL’s to a DB maybe try this code below:
from replit import db
url = "https://google.com"
# url2 = "https://replit.com"
db["urls"] = 
time.sleep(2) # wait before deleting url
del db["urls"] # indicating first val
In this code, im just appending the url to an already existing value then deleting it.