从AWS下载文件的python错误

时间:2017-08-08 22:02:24

标签: python-2.7

我是python的新手,下面的代码会抛出错误。请帮我解决问题。这段代码用于从AMAZON WEB SERVICE(AWS)下载文件。

import boto
import os

cwd = 'T:\\Amazon_receive\\AWS\\'
os.chdir(cwd)

S3_BUCKET = 'User_Name'
ACCESS_KEY = 'Password'
SECRET_KEY = 'aed1234xyz' 
conn = boto.connect_s3(ACCESS_KEY, SECRET_KEY)
bucket = conn.get_bucket(S3_BUCKET, validate=False) 

def feeding_data(name, folder_path):
    if not os.path.exists(os.path.join(cwd, name)):
        os.mkdir(name)
        os.chdir(name)
    else:
        os.chdir(name)
    files = os.listdir()

    for k in bucket.list(prefix=folder_path):
        fn = k.name.split('/')[-1]
        try:
            if fn not in files:
                k.get_contents_to_filename(fn)
        except FileNotFoundError:
            pass

    os.chdir('..')

name = 'most_current_eb'
folder_path = '5776/frontend_5776/custom_output/most_current_eb/'
name = 'most_current_eb'
feeding_data(name, folder_path)

ERROR ##

Traceback (most recent call last):
  File "C:\Python27\EA_Atribution.py", line 35, in <module>
    feeding_data(name, folder_path)
  File "C:\Python27\EA_Atribution.py", line 20, in feeding_data
    files = os.listdir()
TypeError: listdir() takes exactly 1 argument (0 given)
>>> 

谢谢你, 马修乔治

1 个答案:

答案 0 :(得分:0)

由于错误如此清楚地表明:

TypeError: listdir() takes exactly 1 argument (0 given)

你应该向listdir()提供一个参数(正好为1),...目录。