1

在 python 2.7 上使用版本 '0.4.25' 在 moto 上运行,我收到以下错误:NotImplementedError: The get_caller_identity action has not been implemented

import boto3
from moto import mock_sns, mock_sts, mock_sqs

@mock_sts
def test_get_caller_identity():
    sts = boto3.client("sts")
    identity = sts.get_caller_identity()

    identity['Arn'].should.equal('arn:aws:sts::123456789012:user/moto')
    identity['UserId'].should.equal('AKIAIOSFODNN7EXAMPLE')
    identity['Account'].should.equal('123456789012')

def main():
    # Testing
    setup_logger(verbose=True, propagate_lower_levels=True)
    test_get_caller_identity()

if __name__ == '__main__':
    main()

如何重现该问题:重新运行上述脚本

你期望发生的事情:期望通过测试

实际发生了什么

[botocore.cre] [DEBUG]  Looking for credentials via: env
[botocore.cre] [DEBUG]  Looking for credentials via: assume-role
[botocore.cre] [DEBUG]  Looking for credentials via: shared-credentials-file
[botocore.cre] [DEBUG]  Looking for credentials via: config-file
[botocore.cre] [DEBUG]  Looking for credentials via: ec2-credentials-file
[botocore.cre] [DEBUG]  Looking for credentials via: boto-config
[botocore.cre] [DEBUG]  Looking for credentials via: container-role
[botocore.cre] [DEBUG]  Looking for credentials via: iam-role
[botocore.ven] [INFO ]  Starting new HTTP connection (1): 169.254.169.254
[botocore.ven] [DEBUG]  "GET /latest/meta-data/iam/security-credentials/ HTTP/1.1" 200 12
[botocore.ven] [INFO ]  Starting new HTTP connection (1): 169.254.169.254
[botocore.ven] [DEBUG]  "GET /latest/meta-data/iam/security-credentials/default-role HTTP/1.1" 200 134
[botocore.cre] [DEBUG]  Found credentials from IAM Role: default-role
[botocore.loa] [DEBUG]  Loading JSON file: /tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/data/endpoints.json
[botocore.loa] [DEBUG]  Loading JSON file: /tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/data/sts/2011-06-15/service-2.json
[botocore.loa] [DEBUG]  Loading JSON file: /tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/data/_retry.json
[botocore.cli] [DEBUG]  Registering retry handlers for service: sts
[botocore.hoo] [DEBUG]  Event creating-client-class.sts: calling handler <function add_generate_presigned_url at 0x7fcf8cabf0c8>
[botocore.arg] [DEBUG]  The s3 config key is not a dictionary type, ignoring its value of: None
[botocore.end] [DEBUG]  Setting sts timeout as (60, 60)
[botocore.hoo] [DEBUG]  Event before-parameter-build.sts.GetCallerIdentity: calling handler <function generate_idempotent_uuid at 0x7fcf8ca73a28>
[botocore.end] [DEBUG]  Making request for OperationModel(name=GetCallerIdentity) (verify_ssl=/tmp/packages/PyAmazonCACerts/PyAmazonCACerts-1.0.2333.874/build/lib/python2.7/site-packages/amazoncerts/internal_and_external_cacerts.pem) with params: {'body': {'Action': u'GetCallerIdentity', 'Version': u'2011-06-15'}, 'url': u'https://sts.amazonaws.com/', 'headers': {'User-Agent': 'Boto3/1.4.4 Python/2.7.8 Linux/3.2.45-0.6.wd.865.49.315.metal1.x86_64 Botocore/1.5.19'}, 'context': {'client_region': u'aws-global', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7fcf8b9b4210>}, 'query_string': '', 'url_path': '/', 'method': u'POST'}
[botocore.hoo] [DEBUG]  Event request-created.sts.GetCallerIdentity: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7fcf8b9b4110>>
[botocore.aut] [DEBUG]  Calculating signature using v4 auth.
[botocore.aut] [DEBUG]  CanonicalRequest:
POST
/

host:sts.amazonaws.com
x-amz-date:20170301T212849Z
x-amz-security-token:test-session-token

host;x-amz-date;x-amz-security-token
ab821ae955788b0e33ebd34c208442ccfc2d406e2edc5e7a39bd6458fbb4f843
[botocore.aut] [DEBUG]  StringToSign:
AWS4-HMAC-SHA256
20170301T212849Z
20170301/us-east-1/sts/aws4_request
0ed37d6dbf3cd83370ec22b49a11b968f8d4ed0a102165a5a5e6ac7244015a85
[botocore.aut] [DEBUG]  Signature:
32e88e133be1cdb6370cda04d99c09d5496dbbc979e949773d846face9d3e637
[botocore.end] [DEBUG]  Sending http request: <PreparedRequest [POST]>
[botocore.ven] [INFO ]  Starting new HTTPS connection (1): sts.amazonaws.com
[botocore.end] [DEBUG]  Exception received when sending HTTP request.
[botocore.end] [DEBUG]  Exception received when sending HTTP request.
Traceback (most recent call last):
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/endpoint.py", line 204, in _get_response
    proxies=self.proxies, timeout=self.timeout)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/vendored/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/vendored/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 372, in _make_request
    httplib_response = conn.getresponse(buffering=True)
  File "/opt/tmp/packages/Python27/Python27-1.0.8941.2229/build/lib/python2.7/httplib.py", line 1065, in getresponse
    response = self.response_class(*args, **kwds)
  File "/opt/tmp/packages/Python27/Python27-1.0.8941.2229/build/lib/python2.7/httplib.py", line 339, in __init__
    self.fp = sock.makefile('rb')
  File "/tmp/packages/Httpretty/Httpretty-0.6.3.796.161/build/lib/python2.7/site-packages/httpretty/core.py", line 208, in makefile
    self._entry.fill_filekind(self.fd)
  File "/tmp/packages/Httpretty/Httpretty-0.6.3.796.161/build/lib/python2.7/site-packages/httpretty/core.py", line 443, in fill_filekind
    status, headers, self.body = self.callable_body(self.request,self.info.full_url(),headers)
  File "/tmp/packages/Python-moto/Python-moto-0.4.x.13.213/build/lib/python2.7/site-packages/moto/core/responses.py", line 96, in dispatch
    return cls()._dispatch(*args, **kwargs)
  File "/tmp/packages/Python-moto/Python-moto-0.4.x.13.213/build/lib/python2.7/site-packages/moto/core/responses.py", line 139, in _dispatch
    return self.call_action()
  File "/tmp/packages/Python-moto/Python-moto-0.4.x.13.213/build/lib/python2.7/site-packages/moto/core/responses.py", line 165, in call_action
    raise NotImplementedError("The {0} action has not been implemented".format(action))
NotImplementedError: The get_caller_identity action has not been implemented
[botocore.hoo] [DEBUG]  Event needs-retry.sts.GetCallerIdentity: calling handler <botocore.retryhandler.RetryHandler object at 0x7fcf8be84490>
Traceback (most recent call last):
  File "/test/test_boto3_helper2.py", line 20, in <module>
    main()
  File "/test/test_boto3_helper2.py", line 17, in main
    test_get_caller_identity()
  File "/tmp/packages/Python-moto/Python-moto-0.4.x.13.213/build/lib/python2.7/site-packages/moto/core/models.py", line 71, in wrapper
    result = func(*args, **kwargs)
  File "/test/test_boto3_helper2.py", line 8, in test_get_caller_identity
    identity = sts.get_caller_identity()
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/client.py", line 253, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/client.py", line 530, in _make_api_call
    operation_model, request_dict)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/endpoint.py", line 141, in make_request
    return self._send_request(request_dict, operation_model)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/endpoint.py", line 170, in _send_request
    success_response, exception):
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/endpoint.py", line 249, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/retryhandler.py", line 251, in __call__
    caught_exception)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/retryhandler.py", line 269, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/retryhandler.py", line 317, in __call__
    caught_exception)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "/tmp/packages/BotoCore/BotoCore-1.x.249.0/build/lib/python2.7/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
NotImplementedError: The get_caller_identity action has not been implemented
4

1 回答 1

1

这在 moto 项目中得到解决并发布。任何高于 0.4.31 的版本都应该可以工作。更多信息请访问https://github.com/spulec/moto/issues/850

请升级您的摩托车:

pip install 'moto>=0.4.31'
于 2017-04-27T14:55:28.077 回答