简体   繁体   中英

Peculiar error downloading keys/files from S3 bucket - [Errno 1] Operation not permitted

I'm using a python script to get all the files in an S3 bucket. The relevant code snippet is as follow:

        print ("Downloading files...")
        for f in files:
            cwd=os.getcwd()
            fname=cwd+"/"
            fname = fname+f.name
            dir = os.path.dirname(fname)
            if not os.path.exists(dir): 
                    print dir
                    os.makedirs(dir)
            try:
                f.get_contents_to_filename(fname)
            except OSError,e:
                print e

When I do this on a bucket which is used to store log files, I get this error on all the folders in that bucket. Eg for the logs folder here:

Downloading files...
/private/tmp/test/logs
[Errno 1] Operation not permitted: '/private/tmp/test/logs/

Despite the error, all the directories and files get downloaded.

Why does that happen? It does not happen on any other buckets, except for this bucket where log files from other buckets are sent to. Or is it something to do with the code? Or permissions on the bucket. It has the default permissions, nothing that I have changed.

Taking @pavel_form's suggestion, I figured out the problem. I was trying to write a directory as a file. Fixed the code using this block, specifically checking if the basename is empty:

            if (not os.path.basename(fname)==""):
                try:
                    f.get_contents_to_filename(fname)
                except OSError,e:
                    print e

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM