Python - Task Scheduler 0x1
Asked Answered
H

7

5

Having a frustrating time with scheduling a Python script (C:\Python27\test.py), which has the following code:

import xlrd
import csv
with xlrd.open_workbook('Z:/somefile.xls') as wb:
        sh = wb.sheet_by_index(3)
        with open('Z:/somefile.csv', 'wb') as f:
                c = csv.writer(f)
                for r in range(sh.nrows):
                    c.writerow(sh.row_values(r))

This script is supposed to take worksheet 3 in "somefile.xls" and save it into it's own .csv file. When I run it manually from the Python Shell, it works as intended.

Z:\ is a mapped drive located on an entirely different server.

When I try to run from the Task Scheduler, I keep getting the 0x1 result code. I have the Task set up as the following:

  • Run whether user is logged on or not - Do Not Store Password
  • Run with highest privileges
  • Program/script: python.exe
  • Add arguments (optional): "test.py"
  • Start in (optional): C:\Python27

I've read quite a few posts, all with different suggestions, none of which worked.

Anyone else run into this situation before?

Jeff

Harmon answered 2/4, 2014 at 18:47 Comment(1)
You're specifying the full path to your python executable, right?Xanthate
X
8

I ran into this a few weeks ago, Task Scheduler can be a real pain!

For whatever reason, I have never been able to get a script to run when the "Run whether user is logged on or not" option is selected. I spent something like 10 hours on the phone with my IT department trying to figure it out. It can't be done. Un-checking that option should then allow your script to run.

Xanthate answered 2/4, 2014 at 19:31 Comment(4)
Task scheduler is beyond a pain now haha! Just to confirm, you selected "run only when user is logged in", correct?Harmon
@user3473345, correct. I also don't have "Run with highest priveleges" selected, not sure if that will have any impactXanthate
I unselected "Run whether user is logged on or not" option and selected "run only when user is logged in". I ran the task and still got the (0x1) error code unfortunately.Harmon
Unselected the "Run with highest privileges", and it worked!! Thank you very much!Harmon
P
1

I Had the same problem, maybe you can try the following configuration:

  • Program/script: C:\Python27\python.exe (Full path of the program executable)
  • Add arguments (optional): test.py (Name of the file to run)
  • Start in (optional): C:\Python27 (Full path of the folder where the file is)

This configuration works for me. Hope this help.

Polk answered 22/4, 2015 at 7:38 Comment(0)
P
1

I had the same problem and tried all the way above but didn't work.

My configuration (like this):

  • Program/script: python.exe
  • Add arguments (optional): D:\test.py
  • Start in (optional): C:\Python37\

Finally, I make out that I read the file in my python script

pd.read_excel("./xlsx/XXX.xlsx")

I thought it will direct to "D:/xlsx/XXX.xlsx" but it didn't. I changed the code in my script:

pd.read_excel("D:/xlsx/XXX.xlsx")

and it works for me.

Paraboloid answered 20/12, 2021 at 3:1 Comment(0)
D
0

I Had the same problem: But problem was because path had a space between words. "C:/python/pythonw.exe" "E:\python\Sales prog\sales prog111.py" I did: "C:/python/pythonw.exe" "E:\python\Salesprog\salesprog111.py"

Dispatch answered 12/10, 2017 at 14:17 Comment(0)
S
0

I had the similar issues when trying to run as another user privileges. I finally logged in to server with "another user" account and find out that python modules for that user were missing.

I ran the .py script with that user with command line and installed all the missing modules with pip for that user.

Then everything started working perfectly.

Savarin answered 18/1, 2022 at 12:31 Comment(0)
M
0

For anyone running into this problem who is using a virtual environment:

  1. Go to your_project_folder\your_venv\Scripts and find python.exe.
  2. Copy its full path
  3. Use this as the executable for the "Program/Script" option in Task Scheduler (NOT the standard Python install location which you might have found with where python for instance)

This will use the Python instance that contains all your packages to run your code instead of the globally installed version of Python, which may or may not contain them. As a result, it should prevent errors caused by missing packages which can be a common cause of the (0x1) error.

An alternative solution would be to install all of your required packages globally on your machine, though in general, this isn't a great practice.

NOTE: There can be other causes of the (0x1) error, such as if you have bugs in your code, but if all is smooth there and you couldn't get your script to run from the Task Scheduler, this should solve it for you.

Hope this helps!

Monia answered 18/4, 2023 at 21:20 Comment(0)
D
0

This issue can also occur if you have more than one Python script in the directory you are using. The Python terminal would open for half a second then close with runtime errors.

If you have only one script in the directory and put the other script it into a different directory, the scheduled task would execute as expected.

Dobbin answered 29/4 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.