run copy file script in python 27 get path error errno22 in Windows Task Scheduler

Viewed 71

when i run a script in Windows Task Scheduler,got

[Errno 22] invalid mode ('wb') or filename:
'\\172.16.60.16\\\xf1\xee\xba\xcf\\lantian\\FAC\\FAC\xbb\xe3\xd7\xdc\xca\xfd\xbe\xdd\xd4\xb4\\F17\xba\xc5\xbb\xfa\xcc\xa8\xd2\xec\xb3\xa3\xbc\xc7\xc2\xbc\xb1\xed.csv

but i run it in IDLE and console was fine. code down there:

record_dir = r"D:\Record"
target_dir = r"\\172.16.60.16\耦合\lantian\FAC\FAC汇总数据源"
file_path = os.path.join(record_dir, filename)
target_path = os.path.join(target_dir, filename)
shutil.copyfile(file_path, target_path)

is it the encode problem? have try to convert target_path to unicode,but it also won't work

2 Answers

In this condition,it was the path of share which somehow can't access by Windows task scheduler.So i use net use \\172.16.60.16\耦合 every time before i copy file to this share to get this script can access this share.And finally,it works. FYI: in my script the code like this:

delete_drive_cmd = r"net use * /DEL /Y"
create_drive_cmd = r"net use \\172.16.60.16\耦合 /PERSISTENT:NO"
os.system(delete_drive_cmd)
os.system(create_drive_cmd)

and here is the website where i get answer: "https://social.technet.microsoft.com/Forums/en-US/d47d116e-10b9-44f0-9a30-7406c86c2fbe/scheduled-task-wont-run-bat-file?forum=winservermanager"

The "r" removes the double "\" before the ip address you are trying to access. Try to debug the issue using os.path.exists() on the folder you are writing to.

Related