# Buggy code
def add_fields(self, *fields):
    for rec in fields:
        if isinstance(rec, io.IOBase):
            k = guess_filename(rec, "unknown")
            self.add_field(k, rec)
            self._has_io = True

        elif len(rec) == 1:
            k = guess_filename(rec[0], "unknown")
            self.add_field(k, rec[0])
            if isinstance(rec[0], io.IOBase):
                self._has_io = True

        elif len(rec) == 2:
            k, fp = rec
            fn = guess_filename(fp)
            self.add_field(k, fp, filename=fn)
            if isinstance(fp, io.IOBase):
                self._has_io = True

        else:
            k, fp, ft = rec
            fn = guess_filename(fp, k)
            self.add_field(k, fp, contenttype=ft, filename=fn)
            self._has_io = True


# Traceback (AssertionError)
Traceback (most recent call last):
File "bug.py", line 7, in <module>
loop.run_until_complete(aiohttp.request('POST', "http://httpbin.org/post", data=d))
File "/usr/lib64/python3.4/asyncio/base_events.py", line 208, in run_until_complete
return future.result()
File "/usr/lib64/python3.4/asyncio/futures.py", line 243, in result
raise self._exception
File "/usr/lib64/python3.4/asyncio/tasks.py", line 317, in _step
result = coro.throw(exc)
File "/home/pepijn/code/eppserver/env/lib/python3.4/site-packages/aiohttp/client.py", line 111, in request
yield from resp.start(conn, read_until_eof)
File "/home/pepijn/code/eppserver/env/lib/python3.4/site-packages/aiohttp/client.py", line 604, in start
self.message = yield from httpstream.read()
File "/home/pepijn/code/eppserver/env/lib/python3.4/site-packages/aiohttp/streams.py", line 366, in read
return (yield from super().read())
File "/home/pepijn/code/eppserver/env/lib/python3.4/site-packages/aiohttp/streams.py", line 341, in read
yield from self._waiter
File "/usr/lib64/python3.4/asyncio/futures.py", line 348, in __iter__
yield self  # This tells Task to wait for completion.
File "/usr/lib64/python3.4/asyncio/tasks.py", line 370, in _wakeup
value = future.result()
File "/usr/lib64/python3.4/asyncio/futures.py", line 243, in result
raise self._exception
File "/home/pepijn/code/eppserver/env/lib/python3.4/site-packages/aiohttp/client.py", line 496, in write_bytes
request.write(chunk)
File "/home/pepijn/code/eppserver/env/lib/python3.4/site-packages/aiohttp/protocol.py", line 666, in write
chunk is EOF_MARKER), chunk
AssertionError: a

# Fixed code
def add_fields(self, *fields):
    to_add = list(fields)

    while to_add:
        rec = to_add.pop(0)

        if isinstance(rec, io.IOBase):
            k = guess_filename(rec, "unknown")
            self.add_field(k, rec)
            self._has_io = True

        elif isinstance(rec, multidict.MultiDict):
            to_add.extend(rec.items(getall=True))

        elif len(rec) == 1:
            k = guess_filename(rec[0], "unknown")
            self.add_field(k, rec[0])
            if isinstance(rec[0], io.IOBase):
                self._has_io = True

        elif len(rec) == 2:
            k, fp = rec
            fn = guess_filename(fp)
            self.add_field(k, fp, filename=fn)
            if isinstance(fp, io.IOBase):
                self._has_io = True

        else:
            k, fp, ft = rec
            fn = guess_filename(fp, k)
            self.add_field(k, fp, contenttype=ft, filename=fn)
            self._has_io = True