我正在尝试使用带有路径样式网址的s3cmd从我的S3存储桶访问对象。这与Java SDK一样没有问题。
s3Client.setS3ClientOptions(S3ClientOptions.builder()
.setPathStyleAccess(true).build());
我想对s3cmd做同样的事情。我在我的s3conf文件中设置了它:
host_base = s3.eu-central-1.amazonaws.com
host_bucket = s3.eu-central-1.amazonaws.com/%(bucket)s
这适用于桶列表:
$ s3cmd ls
2016-08-24 12:36 s3://test
尝试列出存储桶的所有对象时,出现以下错误:
Traceback (most recent call last):
File "/usr/local/bin/s3cmd", line 2919, in <module>
rc = main()
File "/usr/local/bin/s3cmd", line 2841, in main
rc = cmd_func(args)
File "/usr/local/bin/s3cmd", line 120, in cmd_ls
subcmd_bucket_list(s3, uri)
File "/usr/local/bin/s3cmd", line 153, in subcmd_bucket_list
response = s3.bucket_list(bucket, prefix = prefix)
File "/usr/local/lib/python2.7/site-packages/S3/S3.py", line 297, in bucket_list
for dirs, objects in self.bucket_list_streaming(bucket, prefix, recursive, uri_params):
File "/usr/local/lib/python2.7/site-packages/S3/S3.py", line 324, in bucket_list_streaming
response = self.bucket_list_noparse(bucket, prefix, recursive, uri_params)
File "/usr/local/lib/python2.7/site-packages/S3/S3.py", line 343, in bucket_list_noparse
response = self.send_request(request)
File "/usr/local/lib/python2.7/site-packages/S3/S3.py", line 1081, in send_request
conn = ConnMan.get(self.get_hostname(resource['bucket']))
File "/usr/local/lib/python2.7/site-packages/S3/ConnMan.py", line 192, in get
conn.c.connect()
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 836, in connect
self.timeout, self.source_address)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 8] nodename nor servname provided, or not known
答案 0 :(得分:4)
假设您的配置没有其他问题,那么您使用的值是&#34; host_bucket&#34;是错的。
应该是:
host_bucket = %(bucket)s.s3.eu-central-1.amazonaws.com
或
host_bucket = s3.eu-central-1.amazonaws.com
第二个将用于&#34;路径风格&#34;要使用的。但是,如果您使用的是amazon s3和我建议的第一个host_bucket值,s3cmd将自动使用基于dns或基于路径的存储桶,具体取决于您在存储桶名称中使用的字符。
为什么您只想使用基于路径的样式,这是一个特殊原因吗?