tags:

views:

137

answers:

2

this is particularly at this line:

filesys = os.listdir(settings.CAPTCHA_ROOT)

it happens when trying to read or write to a directory.

any ideas why it would do this only under Windows?

edit ---------------------------------------

 def __clean_captchas(self, offset=3600):
        """docstring for __clean_captchas"""
        filesys = os.listdir(settings.CAPTCHA_ROOT)
        offset = datetime.datetime.now() - datetime.timedelta(seconds=offset)
        for file in filesys:
            d = datetime.datetime.fromtimestamp(os.stat(settings.CAPTCHA_ROOT+file).st_ctime) ...
            if d < offset:
                os.remove(settings.CAPTCHA_ROOT+file)
A: 

If you specify the directory as a constant string, and you're writing the path using backslashes instead of forward slashes, you need to use raw strings. e.g.,

CAPTCHA_ROOT = r'D:\captcha'
Chris Jester-Young
i tried this, still did not work
Rasiel
+1  A: 

Your settings.CAPTCHA_ROOT is incorrect. For portable paths you should avoid slashes and backslashes and use os.path.join function instead, smth. like this:

import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
CAPTHA_ROOT = os.path.join(PROJECT_PATH,'some','sub','folders')
Mike Korobov
thanks! it jumped one line and now iget an error at the following line:for file in filesys: d = datetime.datetime.fromtimestamp(os.stat(settings.CAPTCHA_ROOT+file).st_ctime) ... if d < offset: os.remove(settings.CAPTCHA_ROOT+file)
Rasiel
sorry,see my edit above
Rasiel
so try using os.path.join(settings.CAPTCH_ROOT, file) instead of settings.CAPTCHA_ROOT+file.It would also be helpful if you print the value of your settings.CAPTCH_ROOT. Does it have trailing slash?
Mike Korobov
Great this worksnow i only get an "Access is denied" message when trying os.remove() and i can't get windows to change the permissions. will have to figure this out.. but thanks for all the help
Rasiel