question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mock_s3 does not appear to be working with boto3

See original GitHub issue

This 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:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gwaxcommented, Apr 12, 2016

Interestingly, if you set the region to ‘us-east-1’, your code will probably work. See: #580

0reactions
daidojicommented, Jun 17, 2016

Yeah I’m gonna close this because latest version of moto3 seems to not display this behavior anymore. Thanks to whomever resolved this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocking boto3 S3 client method Python
This answer was great. I first attempted to use stubber, but it only seemed to work for an immediate call, I couldn't get...
Read more >
InvalidAccessKeyId - mocking no longer works · Issue #2413
This issue has been raised many times before it appears, ... of boto3.client in my code into a method to get the mock...
Read more >
Error handling — Boto3 Docs 1.26.32 documentation - AWS
This is a general exception when an error response is provided by an AWS service to your Boto3 client's request. Additional client-side issues...
Read more >
How To Mock AWS Services in Python Unit Tests
We're going to explore the moto library to mock AWS resources. We'll couple it to pytest framework for scalable and clean python unit...
Read more >
How to Efficiently Work with Pandas and S3 | by Simon Hawe
When your code accesses S3, you don't want to access a real S3 bucket in your ... To test these functions, I also...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found