0
昨天我開始使用Amazon S3與博託,我安裝一個python腳本來創建一個桶和上傳圖片的目錄。我跑了好幾次,似乎沒事。連接更改爲博託get_bucket後從Amazon S3關閉錯誤
我不想不斷地創造然而,水桶,所以我適應我的腳本get_bucket:
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')
這個錯誤來自行key.set_contents_from_filename(filename)
此代碼基本上是從博託示例代碼S3入門指南,我把它放到一個循環中。我認爲問題在於它第一次做事是件好事,但不足以應付覆蓋等問題。我是否必須給boto更多的東西而不僅僅是要上傳的文件名?
從腳本的輸出是:包括
[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 <module>
[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
我是新來的這一切,蟒蛇,所以任何幫助,將不勝感激:)
謝謝。該set_acl直接從示例代碼中取出。該錯誤似乎是我設法解決的超時問題,但我現在回家了,無法記住修復程序。儘管我確實將'get_bucket()'更改爲'lookup()',但我不確定它的影響。儘管如果遇到更多問題,我一定會記下該調試命令。謝謝。 – 2012-03-07 17:34:26
順便說一句,lookup()實際上調用了get_bucket()。它們之間的唯一區別是,如果未找到存儲桶並且查找返回無,get_bucket()將引發異常。所以看起來應該沒有什麼區別。 – garnaat 2012-03-08 05:32:03
對,我會回到get_bucket()那麼。我現在在代碼中看到的唯一區別是我在循環後面添加了'time.sleep(2)',然後刪除文件的本地副本。 – 2012-03-08 07:45:00