mock_s3 does not appear to be working with boto3
See original GitHub issueThis sample test script currently fails below. I first noticed this behavior while migrating to python3 and attempting to rewrite some boto code in boto3. The error and sample program are pasted below.
boto3==1.3.0 moto==0.4.23
import boto3
import moto
# This function throws error
@moto.mock_s3
def foo():
conn = boto3.resource('s3')
bucket = conn.Bucket('mybucket')
obj = bucket.Object('myobject')
obj.put(Body='A,B,C')
# This function runs perfectly
def bar():
conn = boto3.resource('s3')
bucket = conn.Bucket('mybucket')
obj = bucket.Object('myobject')
obj.put(Body='A,B,C')
Error from function foo() is
In [39]: foo()
ClientError Traceback (most recent call last) <ipython-input-39-624891b0d01a> in <module>() ----> 1 foo()
/home/daidoji/.virtualenvs/data3/lib/python3.5/site-packages/moto/core/models.py in wrapper(_args, *_kwargs) 69 self.start(reset=reset) 70 try: —> 71 result = func(_args, *_kwargs) 72 finally: 73 self.stop()
<ipython-input-37-552a72c7e731> in foo() 3 bucket = conn.Bucket(‘mybucket’) [0/1197] 4 obj = bucket.Object(‘myobject’) ----> 5 obj.put(Body=‘A,B,C’) 6
me/daidoji/.virtualenvs/data3/lib/python3.5/site-packages/boto3/resources/factory.py in do_action(self, _args, *_kwargs) 496 # instance via
self
. 497 def do_action(self, _args, *_kwargs): –> 498 response = action(self, _args, *_kwargs) 499 500 if hasattr(self, ‘load’):/home/daidoji/.virtualenvs/data3/lib/python3.5/site-packages/boto3/resources/action.py in call(self, parent, _args, *_kwargs) 81 operation_name, params) 82 —> 83 response = getattr(parent.meta.client, operation_name)(**params) 84 85 logger.debug(‘Response: %r’, response)
/home/daidoji/.virtualenvs/data3/lib/python3.5/site-packages/botocore/client.py in _api_call(self, _args, *_kwargs) 226 “%s() only accepts keyword arguments.” % py_operation_name) 227 # The “self” in this scope is referring to the BaseClient. –> 228 return self._make_api_call(operation_name, kwargs) 229 230 _api_call.name = str(py_operation_name)
/home/daidoji/.virtualenvs/data3/lib/python3.5/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params) 490 491 if http.status_code >= 300: –> 492 raise ClientError(parsed_response, operation_name) 493 else: 494 return parsed_response
ClientError: An error occurred () when calling the PutObject operation:
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
Interestingly, if you set the region to ‘us-east-1’, your code will probably work. See: #580
Yeah I’m gonna close this because latest version of moto3 seems to not display this behavior anymore. Thanks to whomever resolved this.