我正在尝试运行这个aws s3 ls命令:
aws s3 ls s3://path/to/my/bucket/12434 --recursive --human-readable --summarize使用这条python:
command = 'aws s3 ls s3://path/to/my/bucket/12434 --recursive --human-readable --summarize'
s3_folder_data = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
print s3_folder_data但它失败了,错误如下:
subprocess.CalledProcessError: Command 'aws s3 ls s3://path/to/my/bucket/12434 --recursive --human-readable --summarize' returned non-zero exit status 1当我运行该命令时,它本身就会工作。python脚本正由同一台计算机上的同一用户调用。怎么回事?
发布于 2016-10-26 02:34:19
正如其他人所建议的,使用Boto3 S3库来获取您想要的东西。但如果您坚持使用subprocess,请尝试:
subprocess.check_output(['aws', 's3', 'ls', 's3://path/to/my/bucket/12434', '--recursive', '--human-readable', '--summarize'])或
subprocess.call(['aws', 's3', 'ls', 's3://path/to/my/bucket/12434', '--recursive', '--human-readable', '--summarize'])并在此基础上继续发展。
发布于 2016-10-26 07:56:56
Python3.5中的新特性,你也可以使用subprocess.run()。
subprocess.run(['aws', 's3', 'ls', 's3://path/to/my/bucket/12434', '--recursive', '--human-readable', '--summarize'])https://stackoverflow.com/questions/40245914
复制相似问题