diff --git a/src/microdot/asgi.py b/src/microdot/asgi.py index caf5b47..2b1e88f 100644 --- a/src/microdot/asgi.py +++ b/src/microdot/asgi.py @@ -130,6 +130,8 @@ class Microdot(BaseMicrodot): try: while not cancelled: # pragma: no branch res_body = await body_iter.__anext__() + if isinstance(res_body, str): + res_body = res_body.encode() await send({'type': 'http.response.body', 'body': res_body, 'more_body': True}) diff --git a/tests/test_asgi.py b/tests/test_asgi.py index d2d2e04..80bed02 100644 --- a/tests/test_asgi.py +++ b/tests/test_asgi.py @@ -35,7 +35,7 @@ class TestASGI(unittest.TestCase): class R: def __init__(self): self.i = 0 - self.body = [b're', b'sp', b'on', b'se', b''] + self.body = [b're', b'sp', b'on', 'se', b''] async def read(self, n): data = self.body[self.i]