Hello all,
when deploying my app on streamlit.share.io, i’m having a classic FileNotFoundError: [Errno 2] No such file or directory.
I am sure of the path (tested it directly from the log file generated). This is strange since, when I’m using the app in standalone mode, it works perfectly as I want. I’ve tried multiple workaround found here on the forum, but for the life of me, I can’t get it to work. I join in attachement the screenshot of what I get. The app itself is running, but i get the error when I copy/past the path of the folder where my file is contained (without the filename, but I tried also with the file name, still fails), it get the error message in the picture. I’ll also join my code. It is part of a multipage app so no worries about the def app() stuff, it’s getting called somewhere else and there is no issue with that. The file is a .log file, but it’s not the cause of the problem either.
At some point, I thought it was the \ vs \ problem with the path, but it appears it is not (maybe yes, but I don’t think so, since I’ve tried a direct raw string or normal string and it works in standalone mode).
Does anyone have any idea?
Edit: the error message is giving a slightly different function name, because it’s from some troubleshooting, but the result is absolutely the same with what I copied here.
You cannot access files on your local computer in this way if you run the streamlit app on streamlit cloud. This does not work and is a conceptual misunderstanding. Think about it, where does this python app run, it runs on the server and there is no C: drive.
ok but then how do you read such a file? Because a “with open(…) as f:” classic way, I’m struggling a lot. I have other pages where I use the file_uploader widget without problems for a csv file, but for my log file, I’m stuck.
Sure, thanks a lot for all the help!
What’s currently uncommented (with the open()…) does not work and returns an error “TypeError: expected str, bytes or os.PathLike object, not UploadedFile”.
I also tried the commented line above instead (with, of course, commenting the open() )) but then my line containing 'if string_to_search in line:" is messed up with types as well. It’s probably simpler than I think, I’m probably noze-dived in it for too long today.
ifile = st.file_uploader("Upload your log file here!", type=".log", accept_multiple_files=False)
line_number = 0
list_of_results = []
ifile=ifile
if ifile is not None:
#f = ifile.readlines()
with open(ifile, "rb") as f:
# Read all lines in the file one by one
for line in f:
# For each line, check if line contains the string
line_number += 1
if string_to_search in line:
# If yes, then add the line number & line as a tuple in the list
if octype == "actual":
line = line.replace(line[24:79], '') # to remove the timestamp of file creation (not the event timestamp)
list_of_results.append(line.replace(oc_id, ''))
else:
line = line.replace(line[0:120], "")
list_of_results.append(line.replace(install_oc, " "))
# Return list of tuples containing line numbers and lines where string is found
return list_of_results
uploaded_file = st.file_uploader("Upload your log file here!", type=".log", accept_multiple_files=False)
if uploaded_file is not None:
lines = uploaded_file.readlines()
for line in lines:
print(line.decode("utf-8").strip())