Hi Streamlits,
I am facing issue in connecting the AWS S3 with streamlit. Kindly find my code below
import streamlit as st
import pandas as pd
DATA_BUCKET = "https://streamlitappdata.s3.ap-south-1.amazonaws.com/"
DATA_URL = DATA_BUCKET + "onehourdatamodelfinal.csv"
read_and_cache_csv = st.cache(pd.read_csv)
data = read_and_cache_csv(DATA_URL, nrows=100000)
st.write('Data', data)
Below is the error am getting.
2022-09-12 11:12:13.170 Uncaught app exception
Traceback (most recent call last):
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/streamlit/runtime/legacy_caching/caching.py", line 584, in get_or_create_cached_value
return_value = _read_from_cache(
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/streamlit/runtime/legacy_caching/caching.py", line 345, in _read_from_cache
raise e
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/streamlit/runtime/legacy_caching/caching.py", line 330, in _read_from_cache
return _read_from_mem_cache(
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/streamlit/runtime/legacy_caching/caching.py", line 248, in _read_from_mem_cache
raise CacheKeyNotFoundError("Key not found in mem cache")
streamlit.runtime.legacy_caching.caching.CacheKeyNotFoundError: Key not found in mem cache
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script
exec(code, module.__dict__)
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/simple.py", line 7, in <module>
data = read_and_cache_csv(DATA_URL, nrows=100000)
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/streamlit/runtime/legacy_caching/caching.py", line 618, in wrapped_func
return get_or_create_cached_value()
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/streamlit/runtime/legacy_caching/caching.py", line 602, in get_or_create_cached_value
return_value = non_optional_func(*args, **kwargs)
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/pandas/util/_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 678, in read_csv
return _read(filepath_or_buffer, kwds)
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 575, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 932, in __init__
self._engine = self._make_engine(f, self.engine)
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1216, in _make_engine
self.handles = get_handle( # type: ignore[call-overload]
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/pandas/io/common.py", line 667, in get_handle
ioargs = _get_filepath_or_buffer(
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/pandas/io/common.py", line 336, in _get_filepath_or_buffer
with urlopen(req_info) as req:
File "/Users/sridharrajaram/Mcg/Projects/Python/simple/.venv/lib/python3.8/site-packages/pandas/io/common.py", line 236, in urlopen
return urllib.request.urlopen(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
Kindly help me in solving the issue, i am new to both AWS and streamlit. I just created s3 bucket and uploaded the csv file and copied the URL and using it in streamlit.
Please help me with some sample code if anybody has how to connect s3 with streamlit.
Regards
Sridhar Rajaram