Skip to content

Async example fails on Python 3.11 when URL is changed to HTTPS #209

Closed
@oschwald

Description

@oschwald

While debugging failures on our test suite with Python 3.11, I noticed that the async example in the docs fail in the same way with Python 3.11 after changing the URL to HTTPS:

import aiohttp
import asyncio

from unittest import TestCase

from mocket import mocketize
from mocket.mockhttp import Entry

class AioHttpEntryTestCase(TestCase):
    @mocketize
    def test_http_session(self):
        url = 'https://httpbin.org/ip'
        body = "asd" * 100
        Entry.single_register(Entry.GET, url, body=body, status=404)
        Entry.single_register(Entry.POST, url, body=body*2, status=201)

        async def main(l):
            async with aiohttp.ClientSession(
                loop=l, timeout=aiohttp.ClientTimeout(total=3)
            ) as session:
                async with session.get(url) as get_response:
                    assert get_response.status == 404
                    assert await get_response.text() == body

                async with session.post(url, data=body * 6) as post_response:
                    assert post_response.status == 201
                    assert await post_response.text() == body * 2

        loop = asyncio.new_event_loop()
        loop.run_until_complete(main(loop))

This fails with:

aiohttp.client_exceptions.ClientOSError: Cannot write to closing transport

It works fine if the URL is just http://httpbin.org/ip.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions