Skip to content

Instantly share code, notes, and snippets.

@buxx
Created July 24, 2018 12:44
Show Gist options
  • Save buxx/d0a749b6673a18a90b47464b79254124 to your computer and use it in GitHub Desktop.
Save buxx/d0a749b6673a18a90b47464b79254124 to your computer and use it in GitHub Desktop.
aiohttp stream response example
from aiohttp import web
async def handle(request):
response = web.StreamResponse(
status=200,
reason='OK',
headers={'Content-Type': 'text/plain'},
)
await response.prepare(request)
with open('aiopocdata.txt', 'r') as file:
for line in file.readlines():
await response.write(line.encode('utf-8'))
await response.write_eof()
return response
app = web.Application()
app.add_routes([
web.get('/', handle)
])
web.run_app(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment