Skip to content

Error in documentation example #4314

Closed
Closed
@vickz84259

Description

Long story short

The Hacking Multipart section on the Working with Multipart page has an example that isn't working as intended.

Expected behaviour

The code given should cater for the scenario where a server may require the Content-Length for the whole multipart request to be specified.

Actual behaviour

The warning: RuntimeWarning: coroutine 'MultipartWriter.write' was never awaited mpwriter.write(writer) is issued and the Content-Length header is set to 0.

Steps to reproduce

Execute the code shown in the Hacking Multipart section after fixing the typo specified in #4312 as shown below:

class Writer:
    def __init__(self):
        self.buffer = bytearray()

    async def write(self, data):
        self.buffer.extend(data)

writer = Writer()
mpwriter.write(writer)
await aiohttp.post('http://example.com',
                   data=writer.buffer, headers=mpwriter.headers)

Your environment

aiohttp == 3.6.2 client

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions