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

[Errno None] Can not write request body for <my_url> with a large number of requests #5818

Open
1 task done
DimaKalbfleysh opened this issue Jun 21, 2021 · 2 comments
Open
1 task done
Labels
invalid This doesn't seem right question StackOverflow reproducer: missing This PR or issue lacks code, which reproduce the problem described or clearly understandable STR

Comments

@DimaKalbfleysh
Copy link

DimaKalbfleysh commented Jun 21, 2021

Describe the bug

The tracker often receives an error that I have not been able to fix and reproduce for a long time.

This is what my client looks like

class Client:
    _auth = (API_USER, API_PASSWORD)

    def __init__(self):
        self.auth = aiohttp.BasicAuth(self._auth[0], self._auth[1])

    async def send(self, url, json, debug=True,):
        try:
            async with aiohttp.ClientSession(
                    connector=aiohttp.TCPConnector(verify_ssl=False),
                    raise_for_status=True,
            ) as session:
                async with session.post(
                        url=url,
                        json=json,
                        auth=self.auth,
                ) as response:
                    if debug:
                        print(f"{url} response.status", response.status, json)
                    if response.status not in [200, 201]:
                        error = False
                        result = None
                        return error, result

                    error = False
                    result = await response.json(content_type=None)

                    if 'error' in result:
                        if debug:
                            print(f'{url} error', result, json)
                        error = True
                        result = None

                    return error, result
        except (
                aiohttp.client_exceptions.ClientResponseError,
                aiohttp.client_exceptions.ClientConnectorError,
                JSONDecodeError,
                TimeoutError,
        ) as e:
            error = True
            result = None
            return error, result
await Client.send(
    url="my_url",
    json=my_json
)

Please tell me what the problem is

To Reproduce

Do not know how

Expected behavior

Send request normally

Logs/tracebacks

ConnectionResetError: Cannot write to closing transport
  File "aiohttp/client_reqrep.py", line 553, in write_bytes
    await self.body.write(writer)
  File "aiohttp/payload.py", line 231, in write
    await writer.write(self._value)
  File "aiohttp/http_writer.py", line 101, in write
    self._write(chunk)
  File "aiohttp/http_writer.py", line 67, in _write
    raise ConnectionResetError('Cannot write to closing transport')
ClientOSError: [Errno None] Can not write request body for <my_url>
  File "__init__.py", line 1182, in handle_exception_to_resp
    resp = await self.handle_exception(exc)
  File "__init__.py", line 1177, in handle_exception
    raise exc
  File "__init__.py", line 559, in _handle_exception
    yield
  File "__init__.py", line 1091, in handle_req_to_resp
    shared_dependencies_error=shared_dependencies_error,
  File "__init__.py", line 1116, in handle_req
    shared_dependencies_error=shared_dependencies_error,
  File "__init__.py", line 808, in handle_req
    result = await call_sync_async(self.func, **values)
  File "__init__.py", line 332, in call_sync_async
    return await call(*args, **kwargs)
  File "aiohttp/client.py", line 1005, in __aenter__
    self._resp = await self._coro
  File "aiohttp/client.py", line 497, in _request
    await resp.start(conn)
  File "aiohttp/client_reqrep.py", line 844, in start
    message, payload = await self._protocol.read()  # type: ignore  # noqa
  File "aiohttp/streams.py", line 588, in read
    await self._waiter

Python Version

$ python --version
3.7

aiohttp Version

$ python -m pip show aiohttp
3.5.4

multidict Version

$ python -m pip show multidict
4.5.2

yarl Version

$ python -m pip show yarl
1.3.0

OS

Ubuntu Linux 16.04

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@webknjaz webknjaz added the reproducer: missing This PR or issue lacks code, which reproduce the problem described or clearly understandable STR label Jun 21, 2021
@webknjaz
Copy link
Member

There's not enough information. With no reproducer, we'll probably just close this. The exception implies that you're attempting to send some data over a closing connection but since you haven't demonstrated what it is that you do, I can't speculate anymore.

@webknjaz webknjaz added question StackOverflow invalid This doesn't seem right and removed bug labels Jun 21, 2021
@DimaKalbfleysh
Copy link
Author

What information do you need to discard? I do not understand in what cases this error occurs.
ClientOSError: [Errno None] Can not write request body for <my_url>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right question StackOverflow reproducer: missing This PR or issue lacks code, which reproduce the problem described or clearly understandable STR
Projects
None yet
Development

No branches or pull requests

2 participants