FileNotFoundError but a neighbor file can find it

126 views Asked by At

Trying to use Cisco confparse. I have two .py files and two .txt files. One python file can parse both .txt files while the other gets FileNotFoundError on parsing both .txt files. All of the files are in the same location:

/Users/christian/Desktop/Networking/Testing//test.py
/Users/christian/Desktop/Networking/Testing//test2.py
/Users/christian/Desktop/Networking/Testing//exampleSwitch.txt
/Users/christian/Desktop/Networking/Testing//exampleSwitch2.txt

test.py works:

from ciscoconfparse import CiscoConfParse

# Parse the config into objects
confprse = CiscoConfParse('exampleSwitch.txt')

# Iterate over all the interface objects
for intf_obj in confprse.find_objects('^interface'):
    print("cisconfparse object: ")
    print(intf_obj)
    print(intf_obj.text)

and test2.py doesnt:

from ciscoconfparse import CiscoConfParse


confprse = CiscoConfParse('exampleSwitch2.txt')

The error is:

[FATAL] CiscoConfParse could not open 'exampleSwitch2.txt'
Traceback (most recent call last):
  File "/Users/christian/Desktop/Networking/Testing/venv/lib/python3.8/site-packages/ciscoconfparse/ciscoconfparse.py", line 233, in __init__
    f = open(config, **self.openargs)
FileNotFoundError: [Errno 2] No such file or directory: 'exampleSwitch2.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/christian/Desktop/Networking/Testing/test2.py", line 4, in <module>
    confprse = CiscoConfParse('exampleSwitch2.txt')
  File "/Users/christian/Desktop/Networking/Testing/venv/lib/python3.8/site-packages/ciscoconfparse/ciscoconfparse.py", line 308, in __init__
    raise RuntimeError
RuntimeError

Not sure what the problem is.

current permissions:

total 32
drwxr-xr-x  8 christian  staff   272 Jul 14 09:54 .
drwxr-xr-x  5 christian  staff   170 Jul 14 09:54 ..
drwxr-xr-x  7 christian  staff   238 Jul 14 10:20 .idea
-rw-r--r--  1 christian  staff   332 Jul 13 10:26 exampleSwitch.txt
-rw-r--r--@ 1 christian  staff   875 Jul 14 09:06 exampleSwitch2.txt
-rw-r--r--  1 christian  staff  1402 Jul 14 09:01 test.py
-rw-r--r--  1 christian  staff   167 Jul 14 09:54 test2.py
drwxr-xr-x  6 christian  staff   204 Jul 14 08:46 venv

Created a new file within PyCharm "exampleSwitch4.txt" Here are the permissions:

(venv) (base) Christians-MBP:Testing christian$ ls -la
total 40
drwxr-xr-x  9 christian  staff   306 Jul 15 12:04 .
drwxr-xr-x  5 christian  staff   170 Jul 15 12:04 ..
drwxr-xr-x  7 christian  staff   238 Jul 15 12:04 .idea
-rw-r--r--@ 1 christian  staff   332 Jul 13 10:26 exampleSwitch.txt
-rw-r--r--  1 christian  staff   875 Jul 14 10:47 exampleSwitch3.txt
-rw-r--r--  1 christian  staff   575 Jul 15 12:04 exampleSwitch4.txt
-rw-r--r--  1 christian  staff  1402 Jul 14 09:01 test.py
-rw-r--r--@ 1 christian  staff   167 Jul 15 12:04 test2.py
drwxr-xr-x  6 christian  staff   204 Jul 14 08:46 venv
1

There are 1 answers

4
AudioBubble On

Make sure that the executing User has the right permissions.