Search code examples
pythonschedulerpythonanywhere

PythonAnywhere Script Scheduler Not Working


Ive got a python script that runs fine when I go to the file and hit run. However the script fails when the scheduler runs it. What could be causing this?

This is my script:

import time
import os
import shutil
import stat

for i in os.listdir():
    if os.path.isdir(i):
         shutil.rmtree(i)

This is the error I get when it is ran by scheduler

Traceback (most recent call last):
  File "filepath/myscript.py", line 7, in <module>
    for i in os.listidir():
TypeError: listdir() takes exactly 1 argument (0 given)

2017-01-25 17:10:12 -- Completed task, took 0.00 seconds, return code was 1.

Im confused why this works when I manually run it but not when the schedule runs it.


Solution

  • You're running it under 2 different Python versions. Python 2 requires a path but Python 3, it's optional and defaults to '.'.