I’m assuming that you’re running this in the code node? The error you’re seeing suggests that Python couldn’t find the file /tmp/test.txt, which means either the file didn’t exist or there was an issue with the path or permissions.
Could you check that you have the correct path and permissions to the file? I also noticed that you’re using smart quotes (‘’ “”) instead of the standard straight quotes (’ "), could you replace them with the standard quotes and try again?
If you’re still unsure what’s causing the issue, could you share your workflow, not just the python code, and what you’re trying to do with it? Would help us reproduce the issue
Tip for sharing your workflow in the forum
Pasting your n8n workflow
Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.
```
<your workflow>
```
Make sure that you’ve removed any sensitive information from your workflow and include dummy data or pinned data as much as you can!
try:
# Define the absolute or relative file path
file_path = "/tmp/test1.txt" # Replace with the actual file path
# Open and read the file
with open(file_path, "r") as file:
file_content = file.read()
# Return the file content
return {
"file_content": file_content
}
except FileNotFoundError:
return {
"error": f"File not found at path: {file_path}"
}
except Exception as e:
return {
"error": str(e)
}
Error: File not found at path: /tmp/test1.txt
Inside the container terminal :
~ $ cat /tmp/test1.txt
111