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

TypeError: _on_request() takes exactly 3 arguments (8 given) #138

Closed
MathMagique opened this issue Feb 15, 2017 · 4 comments
Closed

TypeError: _on_request() takes exactly 3 arguments (8 given) #138

MathMagique opened this issue Feb 15, 2017 · 4 comments
Assignees

Comments

@MathMagique
Copy link

MathMagique commented Feb 15, 2017

I use responses while testing a few calls to a REST API. Calls to the REST API are made using requests.HTTPAdapter.send() (https://github.com/kennethreitz/requests/blob/master/requests/adapters.py#L375)

Mocking these requests with responses fails (at least when I have not prepared responses) with the following error message:

adapter = <requests.HTTPAdapter object at 0x105a8b890>
request = <PreparedRequest [GET]>, a = (False, None, True, None, None)
kwargs = {}

    def unbound_on_send(adapter, request, *a, **kwargs):
>       return self._on_request(adapter, request, *a, **kwargs)
E       TypeError: _on_request() takes exactly 3 arguments (8 given)

unbound_on_send is located in responses. The values for parameter a are the (default) parameters passed to HTTPAdapter.send().

These are the relevant lines in responses:

@beliaev-maksim
Copy link
Collaborator

@MathMagique
can you please provide a snippet to reproduce the issue?

if issue is not reproducible on latest master, please consider closing this issue

@beliaev-maksim
Copy link
Collaborator

@markstory
please close the issue

it is unclear how to reproduce. While we have an example of custom adapter running:

def test_custom_adapter():

@beliaev-maksim beliaev-maksim self-assigned this Jun 22, 2022
@hakjoon
Copy link

hakjoon commented Jun 1, 2023

Let me know if its better to open a new issue.

I am running into this with the 0.1.3.0 release of CacheControl it seems to only occur if you explicitly pass the arguments that HTTPAdpater.send if you just pass along *args, **kwargs it all seems to work.

Here is an adapted test based on the existing custom adapter test. It demonstrates the difference between the two calling patterns.

import requests
import responses
from responses.tests.test_responses import assert_response


def test_passing_custom_adapter():
    @responses.activate
    def run():
        url = "http://example.com"
        responses.add(responses.GET, url, body=b"test")

        calls = [0]

        class DummyAdapter(requests.adapters.HTTPAdapter):
            def send(self, *a, **k):
                calls[0] += 1
                return super().send(*a, **k)

        # Test that the adapter is actually used
        session = requests.Session()
        session.mount("http://", DummyAdapter())

        session.get(url, allow_redirects=False)
        assert calls[0] == 1

        # Test that the response is still correctly emulated
        session = requests.Session()
        session.mount("http://", DummyAdapter())

        resp = session.get(url)
        assert_response(resp, "test")

    run()


def test_breaking_custom_adapter():
    @responses.activate
    def run():
        url = "http://example.com"
        responses.add(responses.GET, url, body=b"test")

        calls = [0]

        class DummyAdapter(requests.adapters.HTTPAdapter):
            def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
                calls[0] += 1
                return super().send(request, stream, timeout, verify, cert, proxies)

        # Test that the adapter is actually used
        session = requests.Session()
        session.mount("http://", DummyAdapter())

        session.get(url, allow_redirects=False)
        assert calls[0] == 1

        # Test that the response is still correctly emulated
        session = requests.Session()
        session.mount("http://", DummyAdapter())

        resp = session.get(url)
        assert_response(resp, "test")

    run()

The environment is

requests==2.31.0
responses==0.23.1

@beliaev-maksim
Copy link
Collaborator

@hakjoon
please open the new issue https://github.com/getsentry/responses/issues/new?assignees=&labels=&projects=&template=bug_report.yml

and add traceback and all relevant info
If all the sufficient info will be present, then I can have a look ASAP

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

No branches or pull requests

4 participants