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!
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!
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!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.