您的位置:首页 > 编程语言 > Python开发

OSError: [Errno 2] No such file or directory

2015-05-29 14:42 609 查看
执行Python脚本时,报如下错误:
['mkdir -p /tmp/gluster_volume_files.can.not.delete']
[E 150529 11:36:14 web:1030] Uncaught exception GET /api/v1/volume/df/tank (10.58.164.150)
HTTPRequest(protocol='http', host='10.160.140.23:8000', method='GET', uri='/api/v1/volume/df/tank', version='HTTP/1.1', remote_ip='10.58.164.150', body='', headers={'Connection': 'keep-alive', 'Accept-Language': 'zh-CN,zh;q=0.8', 'Accept-Encoding': 'gzip, deflate, sdch', 'Cache-Control': 'max-age=0', 'Host': '10.160.140.23:8000', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36'})
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/tornado/web.py", line 987, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "/root/dzq/workspace/tools/glusterfs-rest/glusterrest/restapi.py", line 214, in get
self.write(volume_df(vol))
File "/root/dzq/workspace/tools/glusterfs-rest/glusterrest/restapi.py", line 90, in volume_df
return run_and_response(volume.df, [vol])
File "/root/dzq/workspace/tools/glusterfs-rest/glusterrest/restapi.py", line 44, in run_and_response
return resp_success(func(*args))
File "/root/dzq/workspace/tools/glusterfs-rest/glusterrest/cli/volume.py", line 399, in df
utils.checkstatuszero(cmd1)
File "/root/dzq/workspace/tools/glusterfs-rest/glusterrest/utils.py", line 29, in checkstatuszero
rc, out, err = execute(cmd)
File "/root/dzq/workspace/tools/glusterfs-rest/glusterrest/utils.py", line 21, in execute
close_fds=close_fds)
File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

解决方案:
方案1:Popen中加shell=true选项。
方案2:将命令更为如下形式传入:cmd = ['mkdir'] + ['-p'] + ['/tmp/gluster_volume_files.can.not.delete']

参考:http://stackoverflow.com/questions/901982/python-oserror-errno-2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Python Popen