Python - 如何解决操作系统错误:[Errno 2]没有这样的文件或目录?

时间:2018-02-06 04:46:16

标签: python amazon-web-services amazon-s3 subprocess command-line-interface

我正在运行此命令:

AWS_PROFILE=sandbox aws s3 cp local_path bucket --recursive

这很好用。我想运行一个python脚本。这是我的代码:

cmd = ['AWS_PROFILE=sandbox', 'aws', 's3', 'cp', local_path, bucket, '--recursive']
subprocess.Popen(cmd).communicate()

并且它不起作用。

错误追溯:

File "bin/run_report.py", line 128, in main
    subprocess.Popen(cmd).communicate()
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1025, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

我不明白我做错了什么。我已经三次检查了本地和存储桶的路径,如上所述,它可以从shell运行(我不想运行shell = True)

1 个答案:

答案 0 :(得分:1)

使用<?php session_start(); if(!isset($_SESSION['u_uid'])){ header("Location: http://motoko.sorainsurance.com.au"); } $uid = $_SESSION['u_id']; require_once('connect.php'); $ReadSql = "SELECT * FROM `contact` WHERE users_id=$uid ORDER BY Name"; $res = mysqli_query($connection, $ReadSql); ?> <!DOCTYPE html> <html> <head> <title>Motoko</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script> </head> <body> <div class="container"> <div class="row"> <table class="table"> <tr> <th> <strong>Extras</strong> </th> </tr> <?php while($r = mysqli_fetch_assoc($res)){ ?> <tr> <td> <a href="update.php?id=<?php echo $r['id'] ?>">Edit</a> </td> <td> <input type="button" onClick="deleteme('<?php echo $r['u_uid']; ?>')" name="Delete" value="Delete"> </td> </tr> <?php } ?> </table> </div> </body> </html> <script language="Javascript"> function deleteme(delid){ if(confirm("Are you sure you want to Delete?")){ window.location.href='delete.php?del_id=delid'; } } </script> cli aws开关选择个人资料。

--profile

该命令现在应为:

cmd = ['aws', '--profile=sandbox', 's3', 'cp', '--recursive', local_path, bucket]
print(' '.join(cmd))
subprocess.Popen(cmd).communicate()