It’s unlikely that this is actually what you mean for requirements.txt, which means there won’t be a package from pip to install. A quick Google search suggests that you might mean something like
I recall installing the packages, but how to import them through Google search was not considered. I went to the docs and don’t see there either. I appreciate if you have a direct link to your solution. Appreciate
OK, I have implemented the above Randy and I unfortunately having a bear of a time with the Cloud approach. My local is working perfectly and I have gone to the website to drop in the secret_file info. Can I provide you a link to my site for your observation? I would certainly appreciate it.
I am getting this following error…"Traceback:
File “/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py”, line 354, in _run_script
exec(code, module.dict)
File “/app/pocket_option-strategy-analyzer/app.py”, line 26, in
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
File “/home/appuser/venv/lib/python3.7/site-packages/google/oauth2/service_account.py”, line 239, in from_service_account_file
filename, require=[“client_email”, “token_uri”]
File “/home/appuser/venv/lib/python3.7/site-packages/google/auth/_service_account_info.py”, line 72, in from_filename
with io.open(filename, “r”, encoding=“utf-8”) as json_file:
"
Do you have a working example of a GoogleSheet working with the Streamlit Cloud? I have experienced everything else working nicely, but not this scenario.
I thought I would look for a working example of this scenario in the community and it does not appear to be anywhere even as a effort. I see the effort for using Google Sheets, but not on the Streamlit Cloud Share, just in the docs with a localhost implementation.
Successfully installed cachetools-4.2.4 certifi-2021.10.8 charset-normalizer-2.0.7 google-api-core-2.2.2 google-api-python-client-2.31.0 google-auth-2.3.3 google-auth-httplib2-0.1.0 google-auth-oauthlib-0.4.6 googleapis-common-protos-1.53.0 httplib2-0.20.2 idna-3.3 oauthlib-3.1.1 protobuf-3.19.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 pyparsing-3.0.6 requests-2.26.0 requests-oauthlib-1.3.0 rsa-4.7.2 setuptools-59.1.1 six-1.16.0 uritemplate-4.1.1 urllib3-1.26.7
WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
You should consider upgrading via the '/home/appuser/venv/bin/python -m pip install --upgrade pip' command.
[manager] Python dependencies were installed from /app/pocket_option-strategy-analyzer/requirements.txt using pip.
[manager] Processed dependencies!
2021-11-17 15:51:58.871 Uncaught app exception
Traceback (most recent call last):
File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 354, in _run_script
exec(code, module.__dict__)
File "/app/pocket_option-strategy-analyzer/app.py", line 26, in <module>
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
File "/home/appuser/venv/lib/python3.7/site-packages/google/oauth2/service_account.py", line 239, in from_service_account_file
filename, require=["client_email", "token_uri"]
File "/home/appuser/venv/lib/python3.7/site-packages/google/auth/_service_account_info.py", line 72, in from_filename
with io.open(filename, "r", encoding="utf-8") as json_file:
FileNotFoundError: [Errno 2] No such file or directory: 'keys.json'
[client] Connecting...
The library is trying to read a file that doesn’t exist in your Git repo. I would guess it’s this line here:
I saw this in the error, and I placed the file in the same folder so the path would not be necessary, however, I guess I have to place this in the .streamlit folder and upload that to Github ?
Thanks for your insight on this. It’s getting pretty exciting to be approaching the finish line on this.
Please clarify this view of where I am currently at.
I see where you can place secrets for a local .streamlit folder, however for a Cloud hosting I don’t see how to hide the key.json file in GitHub. I am thinking to just upload the .streamlit folder and reference the file?
Do you have a example of what this looks like in the docs ?
You wouldn’t commit the file to GitHub, because then the values would be publicly accessible to anyone. Instead, you use the secrets management piece to pass in those values.
What this implies though is that you’ll likely need to change the method you use for your authentication (that I highlighted before), not to read from a file but instead pass those arguments directly. In your Python code, you would call the secret value (so it wouldn’t be accessible to everyone), but Python would swap in those values and make your app work.
OK, I see what you are saying, but how to implement is really challenging for me. So I currently have a variable (SERVICE_ACCOUNT_FILE) holding the path of where my file is.
This path is being used in a function,
creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
How do I pass the different components within the file to the places they being used in the function.
I am glad you are helping me to see the issue. I am starting to see the problem, but how to apply your solution is beyond me. lol Hint please…
Oh, now I hear what you are saying, but is that a Oautho2 approach ? What method can work for this type of challenge ?
To me this sounds like a totally different Python Library to build out the code.
Or is it a simple adjustment of existing code ?
This also appears to need a .toml file, not a .json file. Am I on the write track with this ? I do appreciate your thoughts, because I was a little challenged with this and not sure if I needed to scrap my code and build from scratch or if there is a way to make this work with a minor adjustment to existing code. I am scratching my head, lol
You would find an equivalent function to creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES), but that takes the arguments directly.
In this example, we show how to add your credentials through the Streamlit Cloud secrets interface:
And how to authenticate assuming that you are using Streamlit Cloud:
import streamlit as st
from google.oauth2 import service_account
from gsheetsdb import connect
# Create a connection object.
credentials = service_account.Credentials.from_service_account_info(
st.secrets["gcp_service_account"],
scopes=[
"https://www.googleapis.com/auth/spreadsheets",
],
)
conn = connect(credentials=credentials)
This is such jewel of an answer for this question.
I hope I asked the question properly because to have such an eloquent solution makes me feel I did not ask the correct question.
Please advise on what the question should look like so I can properly Notate my code for the Public.
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.