You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
I use deta in a streamlit app.
At each run, the app requests deta to display some info. Also, I created 2 st.text_input and 1 st.button. The button has an on_click input to which I passed a function that requests deta with one get then a put.
When I fill both fields and then click on the button, I get the http.client.CannotSendRequest: Request-sent error.
What is weird is that the error does not occur all the time. It occurs very often when I click on the button directly after editing one of the text input. However, when I click it after having clicked outside the text input first, I never get the error. Also when I put time.sleep(1) before the get request in the on_click function. It also works to do a try except until the request works.
Would you have any idea what happens?
Here is the code to reproduce the error:
db.py
from deta import Deta
from deta.base import _Base
deta = Deta("")
db = deta.Base("data")
def get_user(db: _Base, key: str):
print('before get')
user = db.get(key)
return user if user else None
def update_user(db: _Base, key: str, data: dict):
user = get_user(db, key)
user.update(data)
user = db.put(user, key) # Push data to the db
return user
app.py
import streamlit as st
from streamlit_extras.stateful_button import button as stateful_button # Button that keeps track of its state, so that it works as a toggle button
from db import db, get_user, update_user
def add_new(db, user_key: str):
user = get_user(db, user_key)
new = {'new_a': st.session_state['new_a'], 'new_b': st.session_state['new_b']}
if 'news' in user:
news = user['news'] # news is a list
news.append(new)
else:
news= [new]
update_user(db, user_key, {'news': news})
st.session_state['add'] = False
user_key = ''
user = get_user(db, user_key)
tabs = ['A', 'B', 'C']
management_tab, analysis_tab, questions_tab = st.tabs(tabs)
### Management tab ###
with management_tab:
# There is code where I get data here but I noticed the error can still happen without it (even if less)
if stateful_button('Add', key='add'):
new_a = st.text_input('A', key='new_a')
new_b = st.text_input('B', key='new_b')
send_button = st.button('Send', key='send', on_click=lambda: add_new(db, user_key))
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I use deta in a streamlit app.
At each run, the app requests deta to display some info. Also, I created 2
st.text_input
and 1st.button
. The button has anon_click
input to which I passed a function that requests deta with one get then a put.When I fill both fields and then click on the button, I get the http.client.CannotSendRequest: Request-sent error.
What is weird is that the error does not occur all the time. It occurs very often when I click on the button directly after editing one of the text input. However, when I click it after having clicked outside the text input first, I never get the error. Also when I put
time.sleep(1)
before the get request in the on_click function. It also works to do a try except until the request works.Would you have any idea what happens?
Here is the code to reproduce the error:
db.py
app.py
Thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions