Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moto reset API fails - Connection refused by Responses - the call doesn't match any registered mock #4750

Closed
kogakenji opened this issue Jan 12, 2022 · 5 comments · Fixed by #4749
Labels

Comments

@kogakenji
Copy link

kogakenji commented Jan 12, 2022

I'm using moto==2.0.5 with python 3.7.9.

Test case:

import requests
from moto import mock_s3
import unittest


@mock_s3
class TestMotoReset(unittest.TestCase):
    def test_reset(self):
        requests.post("http://motoapi.amazonaws.com/moto-api/reset")

This gives me the following trace:

Test session starts (platform: darwin, Python 3.7.9, pytest 5.4.2, pytest-sugar 0.9.3)
django: settings:=**.local-settings (from env)
rootdir: /Users/**/src/**, inifile: pytest.ini
plugins: mock-3.1.0, django-3.9.0, sugar-0.9.3, hypothesis-5.14.0, cov-2.8.1
collecting ...

――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― TestMotoReset.test_reset ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

self = <src.lib.tests.example_issue.TestMotoReset testMethod=test_reset>

    def test_reset(self):
>       requests.post("http://motoapi.amazonaws.com/moto-api/reset")

src/lib/tests/example_issue.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.7/site-packages/requests/api.py:119: in post
    return request('post', url, data=data, json=json, **kwargs)
.venv/lib/python3.7/site-packages/requests/api.py:61: in request
    return session.request(method=method, url=url, **kwargs)
.venv/lib/python3.7/site-packages/requests/sessions.py:542: in request
    resp = self.send(prep, **send_kwargs)
.venv/lib/python3.7/site-packages/requests/sessions.py:655: in send
    r = adapter.send(request, **kwargs)
.venv/lib/python3.7/site-packages/responses/__init__.py:842: in unbound_on_send
    return self._on_request(adapter, request, *a, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <responses.RequestsMock object at 0x11c744290>, adapter = <requests.adapters.HTTPAdapter object at 0x11dfd6250>, request = <PreparedRequest [POST]>
kwargs = {'cert': None, 'proxies': OrderedDict(), 'stream': False, 'timeout': None, ...}, match = None, match_failed_reasons = [], resp_callback = None
error_msg = "Connection refused by Responses - the call doesn't match any registered mock.\n\nRequest: \n- POST http://motoapi.amazonaws.com/moto-api/reset\n\nAvailable matches:\n"
i = 0, m = <moto.core.models.CallbackResponse object at 0x11df6b450>

    def _on_request(self, adapter, request, **kwargs):
        # add attributes params and req_kwargs to 'request' object for further match comparison
        # original request object does not have these attributes
        request.params = self._parse_request_params(request.path_url)
        request.req_kwargs = kwargs

        match, match_failed_reasons = self._find_match(request)
        resp_callback = self.response_callback

        if match is None:
            if any(
                [
                    p.match(request.url)
                    if isinstance(p, Pattern)
                    else request.url.startswith(p)
                    for p in self.passthru_prefixes
                ]
            ):
                logger.info("request.allowed-passthru", extra={"url": request.url})
                return _real_send(adapter, request, **kwargs)

            error_msg = (
                "Connection refused by Responses - the call doesn't "
                "match any registered mock.\n\n"
                "Request: \n"
                "- %s %s\n\n"
                "Available matches:\n" % (request.method, request.url)
            )
            for i, m in enumerate(self.registered()):
                error_msg += "- {} {} {}\n".format(
>                   m.method, m.url, match_failed_reasons[i]
                )
E               IndexError: list index out of range

.venv/lib/python3.7/site-packages/responses/__init__.py:813: IndexError
@NielsVanDerWekken
Copy link

NielsVanDerWekken commented Jan 12, 2022

I encounter a very similar issue where my test session has "platform linux -- Python 3.9.7, pytest-6.2.5, py-1.11.0, pluggy-1.0.0", but using a GET request instead of a POST request.
Somehow this only happens when the tests are ran from AWS, while there is no problem when I run them on my own system.
Using moto==2.3.1, requests==2.27.1

This issue started 11 jan 2022. No problems with the exact same code before that date.

@bblommers
Copy link
Collaborator

This issue popped up with the latest release of responses. If you downgrade to 0.16.0, everything should be fine, but Moto does not play well with 0.17.0. (@NielsVanDerWekken I expect that's why it's still working locally, because you're on an older version of responses?)

The intermediate fix is to downgrade responses - we will release a fix soon to make Moto interoperable with the latest version.

@bblommers bblommers added the bug label Jan 12, 2022
@bblommers bblommers pinned this issue Jan 12, 2022
@NielsVanDerWekken
Copy link

I added responses==0.16.0 to our list of requirements (it was automatically downloaded as a dependency before) and this fixed things. Thanks for pointing this out @bblommers !

@bblommers bblommers linked a pull request Jan 12, 2022 that will close this issue
@bblommers
Copy link
Collaborator

Moto >= 2.3.2.dev2 should work with all versions of responses. I've closed this for now, but do let us know if there are still any issues!

@aicharles
Copy link

Just want to say thanks for posting about this issue and the resolution. I had this issue as well as of yesterday and I would have never figured this out on my own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants