Search code examples
pythonpythonanywherefile-read

Script reads text file partially on a scheduled execution


I've encountered a strange issue at PythonAnyWhere.com: File is read normally by a script on manual execution, but only partially on a scheduled execution:

Script

items_list=[]
with open(file) as f: 
    i=1
    for line in f:
        print 'line {0}.: {1}'.format(i, line)
        if i>4:
            temp = line.split()
            single_tuple = temp[0],temp[5]  
            items_list.append(single_tuple)
        i+=1
print items_list

File to read

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file!  Do not edit.

.google.com TRUE    /   FALSE   1507718426  NID  7gVyyZ0xNYH0Rnrvjr
.youtube.com    TRUE    /   FALSE   1512945206  VISITOR_INFO1_LIVE  CgHkhNJriN0

Result in manual exec.:

line 1.: # Netscape HTTP Cookie File
line 2.: # http://curl.haxx.se/rfc/cookie_spec.html
line 3.: # This is a generated file!  Do not edit.
line 4.: 
line 5.: .google.com TRUE / FALSE   1507718426  NID  Ixa47gVyyZ0xNYH0Rnrvjr
line 6.: .youtube.com   TRUE  /  FALSE  1512945206  VISITOR_INFO1_LIVE      CgHkhNJriN0

 [('.google.com', 'NID', ), ('.youtube.com', 'VISITOR_INFO1_LIVE' )]

Result in scheduled exec. (log):

 line 1.: # Netscape HTTP Cookie File
 line 2.: # http://curl.haxx.se/rfc/cookie_spec.html
 line 3.: 
 []
 2017-04-11 11:02:09 -- Completed task, took 1.00 seconds, return code was 1.

What might be a problem?


Solution

  • this is most likely due to a different working directory when you are running the script vs when you are running the scheduled task. try using the full path for your file and see if that fixes it?

    https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory