Created
          July 24, 2018 12:44 
        
      - 
      
- 
        Save buxx/d0a749b6673a18a90b47464b79254124 to your computer and use it in GitHub Desktop. 
    aiohttp stream response example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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