{"id":989,"hash":"c38faad37b1e129d61ce786d6237341ee65dbb9854cd8586efe5bf713e72586c","pattern":"TypeError: &#39;coroutine&#39; object is not iterable","full_message":"I build a chatapplication using Aiohttp server and using python-socket-io. When i tried to host this application in nginx i found this error in supervisor error from error log of supervisor(error log path=  /var/log/gunicorn/gunicorn.err.log )\n\n[2022-05-27 04:16:31 +0000] [32957] [ERROR] Error handling request\n/chatserver Traceback (most recent call last):\nFile \"/home/ubuntu/env/lib/python3.8/site-packages/gunicorn/workers/sync.py\", line 136, in handle\n    self.handle_request(listener, req, client, addr)\nFile \"/home/ubuntu/env/lib/python3.8/site-packages/gunicorn/workers/sync.py\", line 184, in handle_request\n    for item in respiter:\nTypeError: 'coroutine' object is not iterable\n\nThis is my  aiohttp Server Setup.\n\nimport socketio\nfrom aiohttp import web\nimport aiohttp_cors\n\n# create aiohttp application\napp = web.Application()   \n\n# creates a new Async Socket IO Server\nsio = socketio.AsyncServer(\n    cors_allowed_origins='*',\n    cors_credentials=True\n)\n\n# Binds our Socket.IO server to our Web App\nsio.attach(app) \n\ncors = aiohttp_cors.setup(app)\n\n# user esatblish connection with server\n@sio.event\ndef connect(sid, environ):\n\n    @sio.event\n    def set_online(sid, data):\n        \"\"\"\n        set user sid in the dictionary\n        \"\"\"\n        print(sid, data)\n\nasync def index(request):\n    return web.Response(text=\"Welcome home!\")\n\nasync def my_web_app():\n    # ==================== Endpoints =========================\n\n    app.router.add_get('/index', index)\n\n    # ==================== Endpoints =========================\n    \n\n    \"\"\"\n    supervisor execute \n    command( /home/ubuntu/env/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/host-hustle-website/chatapp/app.sock chat:my_web_app )\n    my_web_app func will excecute and app is the created web application(aiohttp instace) is return\n    \"\"\"\n    return app \n\nSupervisor setup in nginx\n\n[program:aio-server]\ncommand=/home/ubuntu/env/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/host-hustle-website/chatapp/app.sock chat:my_web_app\ndirectory=/home/ubuntu/host-hustle-website/chatapp\nautostart=true\nautorestart=true\nstderr_logfile=/var/log/gunicorn/gunicorn.err.log\nstdout_logfile=/var/log/gunicorn/gunicorn.out.log\n\n[group:guni]\nprograms=aio-server\n\nThanks in advance","ecosystem":"pypi","package_name":"python-asyncio","package_version":null,"solution":"I had the same issue, the error was from not using await for async functions.\n\nIn my situation, I had an async function which returned a dictionary , and then another dictionary got updated by that dictionary, This is what I was doing:\n\nasync def make_dict():...\n\ndef update_dict(dict1):\n   dict1.update(make_dict())\n\nBut in order to resolve the error, it should be changed like the following:\n\nasync def make_dict():...\n\ndef update_dict(dict1):\n   dict1.update(await make_dict())\n\nIn your situation, I think you should consider putting an await before calling the index function.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/72400778/typeerror-coroutine-object-is-not-iterable","votes":10,"created_at":"2026-04-19T04:52:07.359377+00:00","updated_at":"2026-04-19T04:52:07.359377+00:00"}