Skip to content

MultipartReader doesn't work with -OO #1969

Closed
@iceboy233

Description

Long story short

MultipartReader doesn't work when -OO is enabled on python interpreter.

Expected behaviour

from aiohttp import web

async def hello(request):
    async for part in await request.multipart():
        print(part.name)
    return web.Response()

app = web.Application()
app.router.add_post('/', hello)
web.run_app(app)
curl 'http://localhost:8080' \
    -H 'content-type: multipart/form-data; boundary=----BOUNDARY' \
    --data-binary $'------BOUNDARY\r\nContent-Disposition: form-data; name="key"\r\n\r\nvalue\r\n------BOUNDARY--\r\n'

Actual behaviour

When -OO is enabled (e.g. python3 -OO a.py), the request handling fails:

Error handling request
Traceback (most recent call last):
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 421, in start
    resp = yield from self._request_handler(request)
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/web.py", line 303, in _handle
    resp = yield from handler(request)
  File "a.py", line 4, in hello
    async for part in await request.multipart():
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/multipart.py", line 560, in __anext__
    part = yield from self.next()
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/multipart.py", line 594, in next
    yield from self._read_boundary()
  File "/home/iceboy/.local/lib/python3.5/site-packages/aiohttp/multipart.py", line 689, in _read_boundary
    % (chunk, self._boundary))
ValueError: Invalid boundary b'', expected b'------BOUNDARY'

Your environment

python 3.5.2
aiohttp 2.1.0

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions