0

The python file begins to get executed but them, error I get is -


Time : 2018-12-26 13:00:01.751099 Traceback (most recent call last):

File "/home/username/public_html/cgi-bin/pull.py", line 13, in <module>
   df = pd.read_csv('Datasets/MC_Master.csv')
File "/home/username/.local/lib/python3.5/site- 
packages/pandas/io/parsers.py", line 678, in parser_f
  return _read(filepath_or_buffer, kwds)

File "/home/username/.local/lib/python3.5/site- 
packages/pandas/io/parsers.py", line 440, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)

File "/home/username/.local/lib/python3.5/site-packages/pandas/io/parsers.py", line 787, in __init__
self._make_engine(self.engine)

File "/home/username/.local/lib/python3.5/site-packages/pandas/io/parsers.py", line 1014, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)

File "/home/username/.local/lib/python3.5/site-packages/pandas/io/parsers.py", line 1708, in __init__
self._reader = parsers.TextReader(src, **kwds)

File "pandas/_libs/parsers.pyx", line 384, in pandas._libs.parsers.TextReader.__cinit__

File "pandas/_libs/parsers.pyx", line 695, in pandas._libs.parsers.TextReader._setup_parser_source

**FileNotFoundError: File b'Datasets/MC_Master.csv' does not exist**

The file MC_Master.csv is contained within cgi-bin/Datasets

PS: it works perfectly using shebang command $ python3 pull.py while i am in the cgi-bin directory.

Any guidance would be appreciated.

2 Answers 2

2

You must use absolute path for the dataset. Try changing Dataset/file.csv to /cgi-bin/Dataset/file.csv or whatever the absolute path is.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it worked! Much appreciated. As suggested, I have used absolute path.
What should be the file permissions for cronjob execution?
1

This is because you are using relative path in your script, when you are working from cgi-bin directory, the relative paths are working fine but while running with cron, a program is executed with user's home directory as working directory. To overcome this problem, as @Gaurav mentioned, use absolute path in scripts, or just change current working directory within the program using os.chdir('/path/to/cgi-bin') before accessing the files.

1 Comment

do NOT use os.chdir() - this is brittle at best -, use absolute path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.