Rasiel
Rasiel

Reputation: 2913

on windows with django i get a WindowsError (3, 'The system cannot find the path specified')

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)

Upvotes: 0

Views: 2359

Answers (2)

Mikhail Korobov
Mikhail Korobov

Reputation: 22238

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')

Upvotes: 2

C. K. Young
C. K. Young

Reputation: 222973

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'

Upvotes: 0

Related Questions