IndexError: list index out of range

225 views
Skip to first unread message

mani iyer

unread,
Jul 22, 2010, 4:16:17 PM7/22/10
to boto-users
hi this is my code am trying to download files from my S3 bucket

say name of the bucket is abc and i have a file under 123 under which
i have a lot of files. The directory structure is like

abc bucket
|
|---123
|
|
|-----file1
|----file2 and so on

The code that I have written is as follows

#!/usr/bin/python

import boto
from boto.s3.connection import S3Connection
access_key = 'xyz'
secret_key = 'asafd'
bucket_name = 'abc'
s3 = S3Connection(access_key, secret_key)

print "connection intiated..."

bucket = s3.get_bucket(bucket_name)

print "retrieving bucket"

inputsetName = '123'

for key in bucket.get_all_keys():

strs = key.name.split('/') #trying to access the directory
structure for the file I want using split function

if (strs[0] != inputsetName):
pass

key.get_contents_to_filename(strs[1])

print "process completed..."



This throws up an error saying

Traceback (most recent call last):
File "download.py", line 27, in <module>
key.get_contents_to_filename(strs[1])
IndexError: list index out of range

Any suggestions/comments?

thanks in advance

Mark Rathwell

unread,
Jul 22, 2010, 4:30:23 PM7/22/10
to boto-...@googlegroups.com
if key.name does not contain '/', then len(strs) will be 1, so strs[1] will be out of range.  

I think maybe you mean to use 'continue', not 'pass' in your conditional.  pass in python means do nothing, continue will run the next iteration of the current loop.



--
You received this message because you are subscribed to the Google Groups "boto-users" group.
To post to this group, send email to boto-...@googlegroups.com.
To unsubscribe from this group, send email to boto-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/boto-users?hl=en.


mani iyer

unread,
Jul 22, 2010, 4:53:20 PM7/22/10
to boto-...@googlegroups.com
Thanks a lot Mark!
--
regards,
manikandan pushpavaneswaran

Mihai Ibanescu

unread,
Jul 22, 2010, 5:17:41 PM7/22/10
to boto-...@googlegroups.com
if you replaced that "pass" with a "continue", your code would work.

mani iyer

unread,
Jul 22, 2010, 5:20:29 PM7/22/10
to boto-...@googlegroups.com
yes it worked!

Thanks All!
Reply all
Reply to author
Forward
0 new messages