Hello friends.
I get the following error on trying to access a particular subpage of my flask web app:
2022-12-16 10:08:26,145: Exception on /ru [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/home/relchron/relchron_1/app.py", line 16, in ru
oldest_variety, newest_variety = get_abbr("data/examples_ru.csv")
File "/home/relchron/relchron_1/app.py", line 154, in get_abbr
with filepath.open(encoding="utf-8-sig", newline='') as infile:
File "/usr/local/lib/python3.10/pathlib.py", line 1119, in open
return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: 'data/examples_ru.csv'
This is the offending line of code:
filepath = Path("data/examples_ru.csv")
print("Filepath exists:", filepath.exists())
with filepath.open(encoding="utf-8-sig", newline='') as infile:
[...]
I have also tried the following:
with open("data/examples_ru.csv", encoding="utf-8-sig", newline='') as infile:
The file "data/examples_ru.csv" is in the appropriate directory. Everything works when I run flask locally, it's just on pythonanywhere that it fails. Locally, the debug line with filepath.exists() returns True. On pythonanywhere I don't see the statement (not sure where to look).
Here's more complete context for the function calls (this is my app.py which sits at the root):
@app.route("/ru")
def ru():
oldest_variety, newest_variety = get_abbr("data/examples_ru.csv")
[...]
def get_abbr(examples_file_path):
filepath = Path(examples_file_path)
print("Filepath exists:", filepath.exists())
with filepath.open(encoding="utf-8-sig", newline="") as infile:
[...]
Here's some printouts about file paths from my console:
11:07 ~/relchron_1/data (main)$ ls
examples_ru.csv examples_ru.json sound_changes_hr.csv sound_changes_hr.json sound_changes_ru.csv sound_changes_ru.json
11:07 ~/relchron_1/data (main)$ pwd
/home/relchron/relchron_1/data
11:08 ~/relchron_1 (main)$ ls
README.md __pycache__ app.py data static templates
11:08 ~/relchron_1 (main)$ pwd
/home/relchron/relchron_1
What is going wrong?