Skip to content

Commit

Permalink
Don't use s3 bucket_head to check for bucket existence
Browse files Browse the repository at this point in the history
This is about
piskvorky#314

This code caused problems when you have write permission to an s3
bucket path but not read permission to the bucket root.

This code was added to prevent implicit bucket creation (to fix issue
154) but it appears that it is no longer needed.
  • Loading branch information
toby cabot committed May 18, 2019
1 parent 2dc8d60 commit f151e4c
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions smart_open/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,17 +418,12 @@ def __init__(
multipart_upload_kwargs = {}

s3 = session.resource('s3', **resource_kwargs)

#
# https://stackoverflow.com/questions/26871884/how-can-i-easily-determine-if-a-boto-3-s3-bucket-resource-exists
#
try:
s3.meta.client.head_bucket(Bucket=bucket)
self._object = s3.Object(bucket, key)
self._min_part_size = min_part_size
self._mp = self._object.initiate_multipart_upload(**multipart_upload_kwargs)
except botocore.client.ClientError:
raise ValueError('the bucket %r does not exist, or is forbidden for access' % bucket)
self._object = s3.Object(bucket, key)
self._min_part_size = min_part_size
self._mp = self._object.initiate_multipart_upload(**multipart_upload_kwargs)

self._buf = io.BytesIO()
self._total_bytes = 0
Expand Down

0 comments on commit f151e4c

Please sign in to comment.