Mohamed-512 / Extra-Streamlit-Components

An all in one place, to find complex or just not available components by default on streamlit.
Apache License 2.0
466 stars 59 forks source link

cannot get cookies #22

Closed cwk0099 closed 1 year ago

cwk0099 commented 2 years ago

image image

Mohamed-512 commented 2 years ago

Have you tried cookie_manager.get_all().get(cookie)? If this doesn't work then you might need to refresh the CookieManager object before getting the cookie by placing this line before your get call: cookie_manager.get_all(key="A totally unique key just to trigger a refresh").

cwk0099 commented 2 years ago

yes, i tried ,and cookie_manager.get_all returns {}

saedx1 commented 2 years ago

This might not be the case here; but I had a similar issue and it was because the cookie is HttpOnly

murtazayusuf commented 2 years ago

Hi, how did you solve the issue @saedx1. I am using streamlit authenticator for my app which uses extra-streamlit-components' cookie manager. It was working fine when the app was deployed only on http, but after got the tls certificate and deployed the server with tls encryption, the cookie manage seems to have trouble loading cookies or saving them. Can you help please?

esePuente commented 2 years ago

Is there a way to set/delete cookies that are HttpOnly?

blipk commented 1 year ago

Having this issue as well, works fine when running locally, but cookies are not set when running in streamlit cloud.

I tried to use cookie_manager.get_all().get(cookie) but this gives the following error:

There are multiple identical st.extra_streamlit_components.CookieManager.cookie_manager widgets with key='set'

Are you able to look into this @Mohamed-512 ?

blipk commented 1 year ago

Turns out that Streamlit Cloud runs in a different timezone and I was using Pythons datetime.now() to set the cookie expiry, which the browser treats as local time, so the cookie was expiring instantly.

Had to pass my timezone info to datetime.now(tz=pytz.timezone("Country/Region"))

Luckily my app is mostly going to be used locally, otherwise I would have to create extra code to juggle the user timezone back and forth between the browser and the streamlit back end.

tonylegend commented 1 year ago

The cookie manager worked before I upgraded from 0.1.3 to 0.2.1. The cookies can not be held in the cookie manager now. The streamlit page keeps being refreshed until I got the None from self.token. It worked just fine using the same streamlit version 1.15.0.

tonylegend commented 1 year ago

The cookie manager worked before I upgraded from 0.1.3 to 0.2.1. The cookies can not be held in the cookie manager now. The streamlit page keeps being refreshed until I got the None from self.token. It worked just fine using the same streamlit version 1.15.0.

Just tried cookie_manager.get_all().get(cookie). It works.

zinoubm commented 1 year ago

Hi everyone, In my case, I was trying the Code snippets in the readme.txt, and the problem was that the expiry date was hard coded, cookie_manager.set( cookie, val, expires_at=datetime.datetime(year=2022, month=2, day=2) )

So the Cookie is expired at creation time.

Mohamed-512 commented 1 year ago

The new version of the package provides more control over the cookies set using CookieManager. Also it should fix pre existing bugs.