OSError: [Errno 2] No such file or directory

执行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

解决方案:

方案1:Popen中加shell=true选项。

方案2:将命令更为如下形式传入:cmd = [‘mkdir‘] + [‘-p‘] + [‘/tmp/gluster_volume_files.can.not.delete‘]

参考:http://stackoverflow.com/questions/901982/python-oserror-errno-2

时间: 2024-08-30 11:20:46

OSError: [Errno 2] No such file or directory的相关文章

ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

命令: ansible -i hosts_20 st  -m shell -a 'service zabbix_agentd star'  -K --become ansible -i hosts_20 st  -m shell -a 'lsof -i:10050'  -K --become 在shell模块报错:| FAILED | rc=127 >>/bin/sh: lsof: command not found 在command模块报错:| rc=2 >>[Errno 2]

python文件操作的坑( FileNotFoundError: [Errno 2] No such file or directory...)

环境:Windows8.1, Python3.6  pycharm community 2017 c盘下有一个配置文件:setup 1 with open('c:\\setup','r') as f: 2 f.read() 提示一直很诡异:FileNotFoundError: [Errno 2] No such file or directory: 'c:\\setup' 网上有大量关于Python编码错误导致无法打开文件的解决方法,utf8 gbk2312,尝试过一遍全部无效 最后原因很乌龙:

使用py2exe 将python文件转成exe文件(以及 error: [Errno 2] No such file or directory: 'MSVCP90.dll'解决方法)

用python写程序真的很简单,当我们开发出功能后,特别是带窗体的python程序,需要将python程序转成双击运行的exe程序.我们需要一个第三方模块 py2exe,就是将py转成exe的模块.只需py2exe怎么安装,我这里就不详细说明了,直接到官网上下载对应python的py2exe版本,然后是傻瓜式安装,并且安装好后py2exe模块会自动添加到python的路径中. 然后就简单了,我们在要被转换成exe的py文件目录下新建一个 setup.py 文件,将代码贴进去: #coding=u

关于python中的 “ FileNotFoundError: [Errno 2] No such file or directory: '……'问题 ”

今天在学python时,在模仿一个为图片加上图标并移动到指定文件夹的程序时遇到"FileNotFoundError: [Errno 2] No such file or directory: '1528712892362.jpg'"这个问题. 讲讲解决方案,因为我要处理的十几张图片是位于 'F:\图片' 这个路径下的,但是读取到具体的某一个文件时忘记使用绝对路径,如果没有为文件加上前面的绝对路径的话,我的理解是默认在程序所在的路径作为当前路径来查找的,所以就会报错说找不到文件. 后来加

[Errno 2] No such file or directory

Centos7.5 执行ansible命令报错 问题: [root@m01 ~]# ansible servers -a "hostname|grep web" -i ./hosts 172.16.1.7 | FAILED | rc=2 >> [Errno 2] No such file or directory 原因: 默认使用的是command模块,command模块不能使用管道 解决方法: 使用shell模块执行命令 [root@m01 ~]# ansible ser

Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt

最近安装python,已经安装好,cmd终端中输入python.pip等命令都有用 然而在配置requirements.txt文件过程中,执行语句 “pip install -r requirement.txt” 时报错 “Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'”, 经过一番折腾,查出原因是在执行这一语句前需要先创建requirements.txt 文件,所

Yum:[Errno 5] [Errno 2] No such file or directory

yum安装软件时,可以连接yum 仓库,但是下载安装时失败,报错如下 [email protected]/0 # yum install httpd 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors-internal.yyhu.com * extras: mirrors-internal.yyhu.com * updates: mirrors-internal.yyh

FileNotFoundError: [Errno 2] No such file or directory的解决方法

1.获取当前文件所在路径 basedir = os.path.dirname(__file__) print("basedir:" + basedir) 2.将路径进行拼接 upload_path = os.path.join(basedir, "static/upload", filename) 原文地址:https://www.cnblogs.com/zengsf/p/9882824.html

python smbus IOError: [Errno 2] No such file or directory

1.打开配置文件 sudo nano /boot/config.txt 打开以下选项 "dtparam=i2c_arm=on" ctrl + o 保存 ctrl + x 退出 2.刷新配置文件 sudo raspi-config 3.打开 I2c选项 4.重启 5.再次运行 参考: https://www.raspberrypi.org/forums/viewtopic.php?t=100189 原文地址:https://www.cnblogs.com/sea-stream/p/111