title: Connection closed error from Amazon S3 after changing to boto get_bucket
body: <p>Yesterday I started using Amazon S3 with boto, I setup a python script to create a bucket and upload images in a directory. I ran it several times and it seemed to be okay.</p>
  
  <p>I don't want to constantly be creating buckets however so I adapted my script to get_bucket:</p>
  
  <pre><code>import os
  import boto
  
  s3 = boto.connect_s3()
  bucket = s3.get_bucket('images')
  
  # Run Selenium test process to create images
  
  
  for root, dirs, files in os.walk(imagesPath):
  for name in files:       
     filename = os.path.join(root, name)
     key = bucket.new_key('{0}/{1}/{2}'.format(revisionNumber, images_process, name)) 
     print "Uploading " + filename + " to Amazon S3"
     key.set_contents_from_filename(filename)
     key.set_acl('public-read')
  </code></pre>
  
  <p>The error comes from the line <code>key.set_contents_from_filename(filename)</code></p>
  
  <p>This code is essentially boto sample code from the S3 getting started guide which I've put into a loop. I assume the problem is that its great to do things the first time, but isn't robust enough to cope with overwriting etc. Do I have to give boto more than just the filename to upload?</p>
  
  <p>The output from the script is:</p>
  
  <pre><code> [exec] Uploading images/Add_Employer_Process/20227M/1.png to Amazon S3
   [exec] Traceback (most recent call last):
   [exec]   File "addEmployerProcess.py", line 121, in &lt;module&gt;
   [exec]     k.set_contents_from_filename(filename)
   [exec]   File "C:\Python26\lib\site-packages\boto\s3\key.py", line 969, inset_contents_from_filename
   [exec]     encrypt_key=encrypt_key)
   [exec]   File "C:\Python26\lib\site-packages\boto\s3\key.py", line 902, inset_contents_from_file
   [exec]     size=size)
   [exec]   File "C:\Python26\lib\site-packages\boto\s3\key.py", line 660, insend_file
   [exec]     query_args=query_args)
   [exec]   File "C:\Python26\lib\site-packages\boto\s3\connection.py", line 449, in make_request
   [exec]     override_num_retries=override_num_retries)
   [exec]   File "C:\Python26\lib\site-packages\boto\connection.py", line 829, in make_request
   [exec]     return self._mexe(http_request, sender, override_num_retries)
   [exec]   File "C:\Python26\lib\site-packages\boto\connection.py", line 794, in _mexe
   [exec]     raise e
   [exec] socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host
  </code></pre>
  
  <p>I'm new to all of this, python included, so any help would be appreciated :)</p>