【发布时间】:2013-06-04 11:17:25
【问题描述】:
我正在寻找一个临时目录, 但是当我试图获取目录时使用
tempfile.gettempdir()
它给我的错误
File "/usr/lib/python2.6/tempfile.py", line 254, in gettempdir
tempdir = _get_default_tempdir()
File "/usr/lib/python2.6/tempfile.py", line 201, in _get_default_tempdir
("No usable temporary directory found in %s" % dirlist))
IOError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/home/openerp/openerp-server']
该目录的权限是root拥有的777。
【问题讨论】:
-
我只知道磁盘已满时才会出现此问题,因为该方法通过尝试写入临时文件来找到有效目录。我想这不是你的问题?
-
@BhajunSingh:我对你声称 Python 会通过实际尝试在那里创建文件来确定直接使用哪个文件感到震惊。但这是真的:hg.python.org/cpython/file/2.7/Lib/tempfile.py#l176 - 见
_get_default_tempdir()。不使用os.access()来检查是否可以写入目录似乎很奇怪。 -
我认为@BhajunSingh 是对的,磁盘可能已满。 stackoverflow.com/questions/7518297/…
-
@BrentWashburne 我已经检查了那个答案,然后我会检查磁盘使用情况。