I’m very new to Streamlit so apologies if this is a basic issue. I’m trying to summarize data from my fantasy baseball league in hopes that I can send it out to my leaguemates. Yahoo fantasy’s api requires a login in order to gain the access token, which I did locally, but I’m unsure how to incorporate that into the deployed app. I’m getting these error messages and I assume they have to do with not passing the credentials/access token:
File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
exec(code, module.__dict__)File "/mount/src/streamlit-example/streamlit_app.py", line 4, in <module>
from yahoofantasy import Context
Here’s a link to my github with the very simple python code:
And here’s documentation on the yahoofantasy library, which makes it easier to access the data:
Any help here would be greatly appreciated. Thanks!
Hey @Mat_Swatek ,
If the access token stays persistent with login attempts, I’d suggest just adding it to your app as a streamlit secret. When you deploy your app, the streamlit secret can be the api token and be used for your api.
If it’s a dynamic access token that changes everytime you login in, I’d probably create an api with routes to handle and exchange the tokens- try fastapi. It ties with streamlit very well!
Hope this helps!
Hi, thanks for the reply.
For this api (and using the library yahoofantasy), I logged in through the terminal and then received the access token and refresh token. Every time I run it again through Visual Studio Code, I no longer need to supply my login info. I’m not sure how this would work within Streamlit though, since my notebook does not contain the login info.
I’ve attached a screenshot of the yahoofantasy library’s authentication instructions, which I have followed and successfully gotten to work locally. Just don’t know how to get it to work within Streamlit. Sorry if this is too basic of a question for this forum!
Hi - hoping to get a response to my follow up if possible! I hope this is a small issue to figure out but I’m just totally stuck at this point. Thank you!
I think the answer depends on if/when the access token expires. Assuming the token doesn’t expire, it looks like you could copy the
.yahoofantasy file (which contains the token) after authenticating and add it to the folder for your Streamlit app (check out this related GitHub Issue).
When you use this app, it already knows who you are because you logged in before. Think of it like your phone remembering your Wi-Fi password. So, you won’t need to log in again when using the app in Streamlit. It’s all set up to work smoothly!