FileNotFoundError: [Errno 2] ? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: FileNotFoundError: [Errno 2] ? (/thread-21269.html) Pages:
1
2
|
FileNotFoundError: [Errno 2] ? - JohnnyCoffee - Sep-22-2019 Hi, I have the following code in a class that works perfectly fine when inside it. Now when accessing through another class file presents me with error. Below I demonstrate the class that works: import os class WspApplication: ws_listdir = os.listdir('../application/controllers')This class works when I print inside it. It only presents the error below when I try to access it in another class: ws_listdir = os.listdir('../application/controllers') FileNotFoundError: [Errno 2] No such file or directory: '../application/controllers' Below is the other class: from syscore.wsp_application import WspApplication class WspProtected: def wsm_dir(ws_path): ws_root = WspApplication.ws_listdir if ws_path == ws_root: return 'Info. . .'.encode('utf-8')Can disregard the path parameter in the analysis it works! Obs: These classes are in the same directories, without permissions and using python 3.7.3 RE: FileNotFoundError: [Errno 2] ? - Gribouillis - Sep-22-2019 There must be some issue with .. Try this try: ws_listdir = os.listdir('../application/controllers') except FileNotFoundError as exc from pathlib import Path raise RuntimeError(Path('..').resolve()) from exc RE: FileNotFoundError: [Errno 2] ? - JohnnyCoffee - Sep-22-2019 (Sep-22-2019, 08:27 AM)Gribouillis Wrote: There must be some issue with .. Try thistry: ws_listdir = os.listdir('../application/controllers') except FileNotFoundError as exc from pathlib import Path raise RuntimeError(Path('..').resolve()) from exc this code does not work RE: FileNotFoundError: [Errno 2] ? - Gribouillis - Sep-22-2019 Ok, I forgot a colon at the end of the except... line, sorry RE: FileNotFoundError: [Errno 2] ? - JohnnyCoffee - Sep-22-2019 (Sep-22-2019, 01:08 PM)Gribouillis Wrote: Ok, I forgot a colon at the end of the except... line, sorry didn't solve RE: FileNotFoundError: [Errno 2] ? - Gribouillis - Sep-23-2019 JohnnyCoffee Wrote:didn't solveThis is not an answer. What happened? What was the whole error traceback? One cannot debug without a return from the interpreter. RE: FileNotFoundError: [Errno 2] ? - JohnnyCoffee - Sep-23-2019 (Sep-23-2019, 04:48 AM)Gribouillis Wrote:JohnnyCoffee Wrote:didn't solveThis is not an answer. What happened? What was the whole error traceback? One cannot debug without a return from the interpreter. Have a comment on the code above to know what you did ? RE: FileNotFoundError: [Errno 2] ? - Gribouillis - Sep-23-2019 JohnnyCoffee Wrote:Have a comment on the code above to know what you did ?I raised a new exception to know how python interpretes the .. directory at the moment the error occurs.
RE: FileNotFoundError: [Errno 2] ? - JohnnyCoffee - Sep-23-2019 (Sep-23-2019, 02:45 PM)Gribouillis Wrote:JohnnyCoffee Wrote:Have a comment on the code above to know what you did ?I raised a new exception to know how python interpretes the This was the error generated : Traceback (most recent call last): File "/home/assistant/PycharmProjects/pycoderun/syscore/wsp_application.py", line 13, in wsm_path ws_listdir = os.listdir('../application/controllers') FileNotFoundError: [Errno 2] No such file or directory: '../application/controllers' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.7/wsgiref/handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "coderun.py", line 16, in coderun return [WspProtected.wsm_dir(ws_path)] File "/home/assistant/PycharmProjects/pycoderun/syscore/wsp_protected.py", line 7, in wsm_dir if ws_path == WspApplication.wsm_path(): File "/home/assistant/PycharmProjects/pycoderun/syscore/wsp_application.py", line 16, in wsm_path raise RuntimeError(Path('..').resolve()) from exc RuntimeError: /home/assistant/PycharmProjects 127.0.0.1 - - [23/Sep/2019 12:48:20] "GET / HTTP/1.1" 500 59 Traceback (most recent call last): File "/home/assistant/PycharmProjects/pycoderun/syscore/wsp_application.py", line 13, in wsm_path ws_listdir = os.listdir('../application/controllers') FileNotFoundError: [Errno 2] No such file or directory: '../application/controllers' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.7/wsgiref/handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "coderun.py", line 16, in coderun return [WspProtected.wsm_dir(ws_path)] File "/home/assistant/PycharmProjects/pycoderun/syscore/wsp_protected.py", line 7, in wsm_dir if ws_path == WspApplication.wsm_path(): File "/home/assistant/PycharmProjects/pycoderun/syscore/wsp_application.py", line 16, in wsm_path raise RuntimeError(Path('..').resolve()) from exc RuntimeError: /home/assistant/PycharmProjects 127.0.0.1 - - [23/Sep/2019 12:48:20] "GET /favicon.ico HTTP/1.1" 500 59 RE: FileNotFoundError: [Errno 2] ? - Gribouillis - Sep-23-2019 So you're trying to access /home/assistant/PycharmProjects/application/controllers Does this directory exist? Is it really what you want to do?
|