开发者

mod_python not detecting files when using open()

I am trying to open a file I have in my /var/www/ directory named cardlist.xml. this is the code I am using.

import cgi
import os
open("./cardlist.xml", "r")
def crawlXml():
    return 0

My error is

MOD_PYTHON ERROR

ProcessId: 11361 Interpreter:

'127.0.1.1'

ServerName: '127.0.1.1' DocumentRoot: '/var/www'

URI: '/test.py/crawlXml' Location: None Directory:

'/var/www/' Filename:

'/var/www/test.py' PathInfo:

'/crawlXml'

Phase: 开发者_Go百科'PythonHandler' Handler: 'mod_python.publisher'

Traceback (most recent call last):

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent)

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target result = _execute_target(config, req, object, arg)

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target result = object(arg)

File "/usr/lib/python2.6/dist-packages/mod_python/publisher.py", line 204, in handler module = page_cache[req]

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1059, in getitem return import_module(req.filename)

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 296, in import_module log, import_path)

File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 680, in import_module execfile(file, module.dict)

File "/var/www/test.py", line 4, in open("./cardlist.xml", "r")

IOError: [Errno 2] No such file or directory: './cardlist.xml'

MODULE CACHE DETAILS

Accessed: Sun Feb 14 16:59:58 2010 Generation: 19

_mp_27cc55c5447f9e0aa13691719290c225 { FileName: '/var/www/test.py'

Instance: 85 [RELOAD]

Generation: 19 [ERROR] Modified:

Sun Feb 14 16:40:17 2010 Imported:

Sun Feb 14 16:22:38 2010 }

This is the result of ls -la in the

/var/www/ directory drwxr-xr-x 3 root root 4096 2010-02-14 16:40 . drwxr-xr-x 16 root root 4096 2010-02-14 15:05 .. -rwxr-xr-x 1 root root 4612891 2010-01-30 16:39 cardlist.xml drwxrwx--- 3 root root 4096 2010-02-14 14:31 mtg -rw-r--r-- 1 root root 110 2010-02-14 16:40 test.py -rw-r--r-- 1 root root 111 2010-02-14 16:32 test.py~

Does anyone know what is going wrong?


The working directory might not be the directory of the file. Try using an absolute path, or an explicitly relative path:

import os.path
open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cardlist.xml'))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜