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: RequestInfo.__new__() missing 1 required positional argument: 'real_url'" after upgrading aiohttp to 3.11.0. #263

Closed
cdessez opened this issue Nov 13, 2024 · 3 comments

Comments

@cdessez
Copy link

cdessez commented Nov 13, 2024

aiohttp just released v3.11.0.

Trying to use aioresponses together with aiohttp==3.11.0 leads to the following failure:

>               async with session.get(url) as response:

scratch_164.py:12: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../lib/python3.10/site-packages/aiohttp/client.py:1418: in __aenter__
    self._resp: _RetType = await self._coro
.../lib/python3.10/unittest/mock.py:2217: in _execute_mock_call
    result = await effect(*args, **kwargs)
.../lib/python3.10/site-packages/aioresponses/core.py:512: in _request_mock
    response = await self.match(method, url, **kwargs)
.../lib/python3.10/site-packages/aioresponses/core.py:456: in match
    response_or_exc = await matcher.build_response(
.../lib/python3.10/site-packages/aioresponses/core.py:202: in build_response
    resp = self._build_response(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <aioresponses.core.RequestMatch object at 0x1459d08e0>
url = URL('http://example.com'), method = 'get', request_headers = {}
status = 200, body = b'Yo!', content_type = 'application/json', payload = None
headers = None, response_class = <class 'aiohttp.client_reqrep.ClientResponse'>
reason = 'OK'

    def _build_response(self, url: 'Union[URL, str]',
                        method: str = hdrs.METH_GET,
                        request_headers: Optional[Dict] = None,
                        status: int = 200,
                        body: Union[str, bytes] = '',
                        content_type: str = 'application/json',
                        payload: Optional[Dict] = None,
                        headers: Optional[Dict] = None,
                        response_class: Optional[Type[ClientResponse]] = None,
                        reason: Optional[str] = None) -> ClientResponse:
        if response_class is None:
            response_class = ClientResponse
        if payload is not None:
            body = json.dumps(payload)
        if not isinstance(body, bytes):
            body = str.encode(body)
        if request_headers is None:
            request_headers = {}
        loop = Mock()
        loop.get_debug = Mock()
        loop.get_debug.return_value = True
        kwargs = {}  # type: Dict[str, Any]
>       kwargs['request_info'] = RequestInfo(
            url=url,
            method=method,
            headers=CIMultiDictProxy(CIMultiDict(**request_headers)),
        )
E       TypeError: RequestInfo.__new__() missing 1 required positional argument: 'real_url'

This can be reproduced with the following minimal reproducer:

import aiohttp
from aioresponses import aioresponses
import pytest


@pytest.mark.asyncio()
async def test_aiohttp_3_11_0():
    with aioresponses() as aiohttp_mock:
        url = "http://example.com"
        aiohttp_mock.get(url, status=200, body="Yo!")
        async with aiohttp.ClientSession() as session:
            async with session.get(url) as response:
                body = await response.text()
                print(body)

This test leads to the above failure on aiohttp==3.11.0, but passes on aiohttp==3.10.11.

@bartfeenstra
Copy link

I raised this with aiohttp: aio-libs/aiohttp#9866

@bdraco
Copy link
Contributor

bdraco commented Nov 13, 2024

Fix is here #262

mxr added a commit to mxr/sqlite-export-for-ynab that referenced this issue Nov 14, 2024
pnuckowski/aioresponses#263

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
MoritzWeber0 added a commit to DSD-DBS/capella-collab-manager that referenced this issue Nov 14, 2024
`aiohttp` released a version that breaks aioresponses.
Until the coresponding PR is merged on their side,
stick to aiohttp < 3.11.0

More information: pnuckowski/aioresponses#263
@cdessez cdessez closed this as completed Nov 15, 2024
@cdessez
Copy link
Author

cdessez commented Nov 15, 2024

This is now resolved. Fixed by both:

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

3 participants