宝途文件上传到S3未能在Windows [错误:10054] [英] Boto file upload to S3 failing on Windows [errno: 10054]
问题描述
我想上传一个文件使用博托在Windows 7机S3,但我不断收到一个错误
[错误10054]一个现有的连接被远程主机强行关闭
我的code与S3交互看起来像这样
从boto.s3.connection进口S3Connection
从boto.s3.key导入密钥
康恩= S3Connection(Access_Key_ID,SECRET_KEY)
斗= conn.lookup(bucket_name)
K =密钥(斗)
k.key ='akeynameformyfile
k.set_contents_from_filename(source_path_of_file_to_upload)
上传工作正常使用AWS CLI使用以下命令在同一台机器上的
AWS S3 CP文件名.exe S3:// bucketname / TTT
该文件大小约为200MB
我的操作系统是Windows 7,Python是通过水蟒运行的所有程序包是最新的。宝途是2.25版本
这code无一不精,从同一个网络上的CentOS的框运行。因此,这是一个Windows的问题?
任何帮助将是非常美联社preciated 谢谢! ç
调试输出下面
发送:HEAD / HTTP / 1.1 \ r \ n主机: ACCESS_KEY_ID.test7.s3.amazonaws.com \ r \ nAccept编码: 身份\ r \ nDate:周三,2014年5月14日22时44分31秒格林尼治标准时间\ r \ nContent长度: 0 \ r \ nAuthorization:AWS ACCESS_KEY_ID:SOME_STUFF = \ r \ n用户代理: 宝途/ 2.25。 0的Python / 2.7.5的Windows / 7 \ r \ñ\ r \ N'
回复:HTTP / 1.1 307临时重定向\ r \ N'
标题:X-AMZ-请求ID:8A3D34FB0E0FD8E4
标题:X-AMZ-ID-2: PwG9yzOVwxy21LmcpQ0jAaMchG0baCrfEhAU9fstlPUI307Qxth32uNAOVv72B2L
标题:地点: HTTPS://ACCESS_KEY_ID.test7.s3-ap-southeast-2.amazonaws。 COM /
标题:内容类型:应用程序/ XML
标题:传输编码:分块
标题:日期:星期三,2014年5月14日22点44分31秒格林尼治标准时间
标题:服务器:AmazonS3
发送:HEAD / HTTP / 1.1 \ r \ n主机: ACCESS_KEY_ID.test7.s3-ap-southeast-2.amazonaws.com \ r \ nAccept编码: 身份\ r \ nDate:我们第d,2014年5月14日22时44分31秒格林尼治标准时间\ r \ nContent长度: 0 \ r \ nAuthorization:AWS ACCESS_KEY_ID:SOME_STUFF = \ r \ n用户银ENT: 宝途/ 2.25.0的Python / 2.7.5的Windows / 7 \ r \ñ\ r \ N'
回复:HTTP / 1.1 200 OK \ r \ N'
标题:X-AMZ-ID-2: erataRIpbOrEwOU72VUAqU9AGJ4 / kX5z1 / UD7rJQy9laKDgOyTyVKABMab8f6wGN
标题:X-AMZ-请求ID:2A7BECC45C9BAE7A
标题:日期:星期三,2014年5月14日22时44分33秒格林尼治标准时间
标题:内容类型:应用程序/ XML
标题:传输编码:分块
标题:服务器:AmazonS3
发送:PUT / akeynameformyfile HTTP / 1.1 \ r \ n主机: ACCESS_KEY_ID.test7.s3.amazonaws.com \ r \ nAccept编码: 身份\ r \ nContent - 长度:242642944 \ r \ nContent-MD5:xYOiNcyFKGY1Y / HsYwHQeg == \ r \ nExpect:100-继续\ r \ nDate:周三,2014年5月14日22时44分33秒格林尼治标准时间\ r \ nUser-代理: 宝途/ 2.25.0的Python / 2.7.5的Windows / 7 \ r \ nContent类型: 应用程序/八位字节流\ r \ nAuthorization:AWS ACCESS_KEY_ID:pWs3KwRv9Q5wDnz4dHD3JwvCy / W = \ r \ñ\ r \ N'----------------------------------------------- ----------------------------错误回溯(最近通话 最后一个)
在()12 K =密钥(斗) 13 k.key ='akeynameformyfile
---> 14 k.set_contents_from_filename(full_path_of_file_to_upload)
C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ LIB \站点包\博托\ S3 \ key.pyc 在set_contents_from_filename(SEL楼名,头,更换,CB, num_cb,政策,MD5,reduced_redundancy,encrypt_key)
1313 num_cb,政策, MD5,1314
reduced_redundancy,- > 1315 encrypt_key = encrypt_key)
1316
1317高清set_contents_from_string(个体经营,string_data,标题=无, 取代= TRUE,
C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ LIB \站点包\博托\ S3 \ key.pyc 在set_contents_from_file(个体经营,FP,头,更换,CB,num_cb, 政策,MD5,reduced_redundancy,query_args,encrypt_key,大小, 倒带)1244
self.send_file(FP,头=头,CB = CB,num_cb = num_cb,
1245 query_args = query_args,- > 1246 chunked_transfer = chunked_transfer,大小=)1247
写入的字节数的回报。 1248返回self.size
C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ LIB \站点包\博托\ S3 \ key.pyc
在由send_file(个体经营,FP,头,CB,num_cb,query_args, chunked_transfer,尺寸)
723 self._send_file_internal(FP,头=头,CB = CB,num_cb = num_cb, 724 query_args = query_args,
- > 725 chunked_transfer = chunked_transfer,大小=)
726 727高清_send_file_internal(个体经营,FP,标题=无,CB =无,num_cb = 10, C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ LIB \站点包\博托\ S3 \ key.pyc
在_send_file_internal(个体经营,FP,头,CB,num_cb,query_args, chunked_transfer,大小,hash_algs)
912头, 913发件人=发件人,
- > 914 query_args = query_args
915)
916 self.handle_version_headers(RESP,力= TRUE)
C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ LIB \站点包\博托\ S3 \ connection.pyc 在make_request(个体经营,甲基OD,斗,钥匙,头部,数据,query_args, 发件人,override_num_retries,retry_handler)631的数据,主机auth_path,发件人, 632 override_num_retries = override_num_retries,
- > 633 retry_handler = retry_handler
634)
C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ LIB \站点包\博托\ connection.pyc 在make_request(个体经营,方法,路径,标题,数据,主机auth_path, 发件人,override_num_retries,参数,可以retry_handler)
1028参数,可以 头,数据,主机)
1029返回self._mexe(HTTP_REQUEST,发件人, override_num_retries,- > 1030 retry_handler = retry_handler)1031
1032 DEF接近(个体经营):C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ LIB \站点包\博托\ connection.pyc
在_mexe(个体经营,要求,森德R,override_num_retries,retry_handler)
905如果调用(发件人): 906回应=发件人(连接,request.method,Request的,
- > 907 request.body,request.headers)
908其它: 909 connection.request(request.method,Request的, C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ LIB \站点包\博托\ S3 \ key.pyc
在发送者(http_conn,方法,路径,数据报头)
813 http_conn.send('\ r \ N') 814其他:
- > 815 http_conn.send(块)
816 ALG在沼气池:
817沼气池[ALG] .update(块)
C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ lib目录\ httplib.pyc在 发(个体经营,数据)
803数据块= data.read(块大小)
804其他:
- > 805 self.sock.sendall(数据)
806
807高清_output(个体经营,S):
C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ lib目录\ ssl.pyc在 sendall(个体经营,数据,标志)
227计数= 0
而228(算上<金额):
- > 229 V = self.send(数据[计数:])
230计数+ = V
231返回量
C:\ Users \用户名\ AppData \本地\连续\蟒蛇\ lib目录\ ssl.pyc在 发(个体经营,数据,标志)
196,而真正的:
197尝试:
- > 198ν= self._sslobj.write(数据)
199除外SSLError中,x:
200如果x.args [0] == SSL_ERROR_WANT_READ:
错误:[错误10054]一个现有的连接被强制关闭 远程主机
@garnaat在上面的意见解决了这个给我提了个建议。谢谢!!
出于某种原因,连接到通用端点,然后尝试专门上传到 AP-东南-2
S3端点失败。但是,如果我们使用了 connect_to_region
函数来发起连接,并指定我们想要的终点,一切工作都OK!再次感谢,并在下面工作的例子。
从boto.s3进口connect_to_region
从boto.s3.connection导入位置
从boto.s3.key导入密钥
康恩= connect_to_region(Location.APSoutheast2,
aws_access_key_id = conf.Access_Key_ID,
aws_secret_access_key = conf.Secret_Key)
斗= conn.lookup(bucket_name)#桶位于Location.APSoutheast2
K =密钥(斗)
k.key ='akeynameformyfile
k.set_contents_from_filename(source_path_of_file_to_upload)
I'm trying to upload a file to S3 using boto on a windows 7 machine, but i keep getting an error
[Errno 10054] An existing connection was forcibly closed by the remote host
My code to interact with S3 looks like this
from boto.s3.connection import S3Connection
from boto.s3.key import Key
conn = S3Connection(Access_Key_ID, Secret_Key)
bucket = conn.lookup(bucket_name)
k = Key(bucket)
k.key = 'akeynameformyfile'
k.set_contents_from_filename(source_path_of_file_to_upload)
The upload works fine on the same machine using the AWS CLI with the following command
aws s3 cp filename.exe s3://bucketname/ttt
The file is about 200MB
My OS is Windows 7, python is running through anaconda with all packages up to date. Boto is version 2.25
This code all runs fine from a CentOS box on the same network. So is this a windows issue?
Any help would be much appreciated thanks! c
Debug Output Below
send: 'HEAD / HTTP/1.1\r\nHost: ACCESS_KEY_ID.test7.s3.amazonaws.com\r\nAccept-Encoding: identity\r\nDate: Wed, 14 May 2014 22:44:31 GMT\r\nContent-Length: 0\r\nAuthorization: AWS ACCESS_KEY_ID:SOME_STUFF=\r\nUser-Agent: Boto/2.25. 0 Python/2.7.5 Windows/7\r\n\r\n'
reply: 'HTTP/1.1 307 Temporary Redirect\r\n'
header: x-amz-request-id: 8A3D34FB0E0FD8E4
header: x-amz-id-2: PwG9yzOVwxy21LmcpQ0jAaMchG0baCrfEhAU9fstlPUI307Qxth32uNAOVv72B2L
header: Location: https://ACCESS_KEY_ID.test7.s3-ap-southeast-2.amazonaws.com/
header: Content-Type: application/xml
header: Transfer-Encoding: chunked
header: Date: Wed, 14 May 2014 22:44:31 GMT
header: Server: AmazonS3
send: 'HEAD / HTTP/1.1\r\nHost: ACCESS_KEY_ID.test7.s3-ap-southeast-2.amazonaws.com\r\nAccept-Encoding: identity\r\nDate: We d, 14 May 2014 22:44:31 GMT\r\nContent-Length: 0\r\nAuthorization: AWS ACCESS_KEY_ID:SOME_STUFF=\r\nUser-Ag ent: Boto/2.25.0 Python/2.7.5 Windows/7\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: x-amz-id-2: erataRIpbOrEwOU72VUAqU9AGJ4/kX5z1/UD7rJQy9laKDgOyTyVKABMab8f6wGN
header: x-amz-request-id: 2A7BECC45C9BAE7A
header: Date: Wed, 14 May 2014 22:44:33 GMT
header: Content-Type: application/xml
header: Transfer-Encoding: chunked
header: Server: AmazonS3
send: 'PUT /akeynameformyfile HTTP/1.1\r\nHost: ACCESS_KEY_ID.test7.s3.amazonaws.com\r\nAccept-Encoding: identity\r\nContent -Length: 242642944\r\nContent-MD5: xYOiNcyFKGY1Y/HsYwHQeg==\r\nExpect: 100-Continue\r\nDate: Wed, 14 May 2014 22:44:33 GMT\r\nUser- Agent: Boto/2.25.0 Python/2.7.5 Windows/7\r\nContent-Type: application/octet-stream\r\nAuthorization: AWS ACCESS_KEY_ID:pWs3KwRv9Q5wDnz4dHD3JwvCy/w=\r\n\r\n'--------------------------------------------------------------------------- error Traceback (most recent call last)
in ()12 k = Key(bucket) 13 k.key = 'akeynameformyfile'
---> 14 k.set_contents_from_filename(full_path_of_file_to_upload)
C:\Users\username\AppData\Local\Continuum\Anaconda\lib\site-packages\boto\s3\key.pyc in set_contents_from_filename(sel f, filename, headers, replace, cb, num_cb, policy, md5, reduced_redundancy, encrypt_key)
1313 num_cb, policy, md5, 1314
reduced_redundancy,-> 1315 encrypt_key=encrypt_key)
1316
1317 def set_contents_from_string(self, string_data, headers=None, replace=True,
C:\Users\username\AppData\Local\Continuum\Anaconda\lib\site-packages\boto\s3\key.pyc in set_contents_from_file(self, f p, headers, replace, cb, num_cb, policy, md5, reduced_redundancy, query_args, encrypt_key, size, rewind) 1244
self.send_file(fp, headers=headers, cb=cb, num_cb=num_cb,
1245 query_args=query_args,-> 1246 chunked_transfer=chunked_transfer, size=size) 1247
return number of bytes written. 1248 return self.size
C:\Users\username\AppData\Local\Continuum\Anaconda\lib\site-packages\boto\s3\key.pyc
in send_file(self, fp, headers, c b, num_cb, query_args, chunked_transfer, size)
723 self._send_file_internal(fp, headers=headers, cb=cb, num_cb=num_cb, 724 query_args=query_args,
--> 725 chunked_transfer=chunked_transfer, size=size)
726 727 def _send_file_internal(self, fp, headers=None, cb=None, num_cb=10, C:\Users\username\AppData\Local\Continuum\Anaconda\lib\site-packages\boto\s3\key.pyc
in _send_file_internal(self, fp, headers, cb, num_cb, query_args, chunked_transfer, size, hash_algs)
912 headers, 913 sender=sender,
--> 914 query_args=query_args
915 )
916 self.handle_version_headers(resp, force=True)
C:\Users\username\AppData\Local\Continuum\Anaconda\lib\site-packages\boto\s3\connection.pyc in make_request(self, meth od, bucket, key, headers, data, query_args, sender, override_num_retries, retry_handler)631 data, host, auth_path, sender, 632 override_num_retries=override_num_retries,
--> 633 retry_handler=retry_handler
634 )
C:\Users\username\AppData\Local\Continuum\Anaconda\lib\site-packages\boto\connection.pyc in make_request(self, method, path, headers, data, host, auth_path, sender, override_num_retries, params, retry_handler)
1028 params, headers, data, host)
1029 return self._mexe(http_request, sender, override_num_retries,-> 1030 retry_handler=retry_handler) 1031
1032 def close(self):C:\Users\username\AppData\Local\Continuum\Anaconda\lib\site-packages\boto\connection.pyc
in _mexe(self, request, sende r, override_num_retries, retry_handler)
905 if callable(sender): 906 response = sender(connection, request.method, request.path,
--> 907 request.body, request.headers)
908 else: 909 connection.request(request.method, request.path, C:\Users\username\AppData\Local\Continuum\Anaconda\lib\site-packages\boto\s3\key.pyc
in sender(http_conn, method, path , data, headers)
813 http_conn.send('\r\n') 814 else:
--> 815 http_conn.send(chunk)
816 for alg in digesters:
817 digesters[alg].update(chunk)
C:\Users\username\AppData\Local\Continuum\Anaconda\lib\httplib.pyc in send(self, data)
803 datablock = data.read(blocksize)
804 else:
--> 805 self.sock.sendall(data)
806
807 def _output(self, s):
C:\Users\username\AppData\Local\Continuum\Anaconda\lib\ssl.pyc in sendall(self, data, flags)
227 count = 0
228 while (count < amount):
--> 229 v = self.send(data[count:])
230 count += v
231 return amount
C:\Users\username\AppData\Local\Continuum\Anaconda\lib\ssl.pyc in send(self, data, flags)
196 while True:
197 try:
--> 198 v = self._sslobj.write(data)
199 except SSLError, x:
200 if x.args[0] == SSL_ERROR_WANT_READ:
error: [Errno 10054] An existing connection was forcibly closed by the remote host
@garnaat made a suggestion in the comments above that solved this for me. Thanks!!
For some reason, connecting to the universal endpoint and then trying to upload specifically to the ap-southeast-2
S3 endpoint fails. But if we use the connect_to_region
function to initiate the connection and specify the endpoint we want, everything works a-ok! Thanks again, and working example below.
from boto.s3 import connect_to_region
from boto.s3.connection import Location
from boto.s3.key import Key
conn = connect_to_region(Location.APSoutheast2,
aws_access_key_id=conf.Access_Key_ID,
aws_secret_access_key=conf.Secret_Key)
bucket = conn.lookup(bucket_name) # bucket is located in Location.APSoutheast2
k = Key(bucket)
k.key = 'akeynameformyfile'
k.set_contents_from_filename(source_path_of_file_to_upload)
这篇关于宝途文件上传到S3未能在Windows [错误:10054]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!