Heroku Application Error with Flask Socket-IO

Issue

The app is perfectly working on local but on heroku server it returns Application Error. I suspect the problem might be on Procfile, when I changed it to "web: gunicorn eventlet -w 1 app:app", from "web: gunicorn app:app" it stopped working, I’m new on socketIO and flask, I’ve tried everything I saw on the internet to put on Procfile that works with socketIO but nothing worked.
Please if anyone knows why this is happening please help me.

This is my requirements.txt file:

bidict==0.22.0
brotlipy==0.7.0
certifi==2021.10.8
click==8.1.3
dnspython==2.2.1
eventlet==0.33.1
Flask==2.1.3
Flask-SocketIO==5.2.0
Flask-SQLAlchemy==2.5.1
Flask-WTF==1.0.1
gevent==21.12.0
gevent-websocket==0.10.1
greenlet==1.1.2
gunicorn==20.1.0
importlib-metadata==4.12.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
psycopg2==2.9.3
pycosat==0.6.3
python-engineio==4.3.3
python-socketio==5.7.1
SQLAlchemy==1.4.39
Werkzeug==2.1.2
wincertstore==0.2
WTForms==3.0.1
zipp==3.8.1
zope.event==4.5.0
zope.interface==5.4.0

this is the heroku logs:

2022-08-05T15:16:18.022704+00:00 app[web.1]:
2022-08-05T15:16:18.022716+00:00 app[web.1]: Error: class uri 'eventlet' invalid or not found:
2022-08-05T15:16:18.022716+00:00 app[web.1]:
2022-08-05T15:16:18.022717+00:00 app[web.1]: [Traceback (most recent call last):
2022-08-05T15:16:18.022717+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/util.py", line 99, in load_class
2022-08-05T15:16:18.022718+00:00 app[web.1]: mod = importlib.import_module('.'.join(components))
2022-08-05T15:16:18.022718+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-08-05T15:16:18.022718+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-08-05T15:16:18.022719+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-08-05T15:16:18.022719+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-08-05T15:16:18.022720+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-08-05T15:16:18.022720+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-08-05T15:16:18.022720+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-08-05T15:16:18.022721+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-08-05T15:16:18.022721+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/geventlet.py", line 20, in <module>
2022-08-05T15:16:18.022721+00:00 app[web.1]: from eventlet.wsgi import ALREADY_HANDLED as EVENTLET_ALREADY_HANDLED
2022-08-05T15:16:18.022722+00:00 app[web.1]: ImportError: cannot import name 'ALREADY_HANDLED' from 'eventlet.wsgi' (/app/.heroku/python/lib/python3.10/site-packages/eventlet/wsgi.py)
2022-08-05T15:16:18.022722+00:00 app[web.1]: ]
2022-08-05T15:16:18.022722+00:00 app[web.1]:
2022-08-05T15:16:18.246442+00:00 heroku[web.1]: Process exited with status 1
2022-08-05T15:16:18.357952+00:00 heroku[web.1]: State changed from starting to crashed
2022-08-05T15:16:18.374380+00:00 heroku[web.1]: State changed from crashed to starting
2022-08-05T15:16:23.365045+00:00 heroku[web.1]: Starting process with command `gunicorn -k eventlet -w 1 app:app`
2022-08-05T15:16:24.399378+00:00 app[web.1]:
2022-08-05T15:16:24.399392+00:00 app[web.1]: Error: class uri 'eventlet' invalid or not found:
2022-08-05T15:16:24.399392+00:00 app[web.1]:
2022-08-05T15:16:24.399393+00:00 app[web.1]: [Traceback (most recent call last):
2022-08-05T15:16:24.399393+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/util.py", line 99, in load_class
2022-08-05T15:16:24.399393+00:00 app[web.1]: mod = importlib.import_module('.'.join(components))
2022-08-05T15:16:24.399394+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-08-05T15:16:24.399394+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-08-05T15:16:24.399394+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-08-05T15:16:24.399395+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-08-05T15:16:24.399395+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-08-05T15:16:24.399395+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-08-05T15:16:24.399396+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-08-05T15:16:24.399396+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-08-05T15:16:24.399396+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/geventlet.py", line 20, in <module>
2022-08-05T15:16:24.399397+00:00 app[web.1]: from eventlet.wsgi import ALREADY_HANDLED as EVENTLET_ALREADY_HANDLED
2022-08-05T15:16:24.399397+00:00 app[web.1]: ImportError: cannot import name 'ALREADY_HANDLED' from 'eventlet.wsgi' (/app/.heroku/python/lib/python3.10/site-packages/eventlet/wsgi.py)
2022-08-05T15:16:24.399398+00:00 app[web.1]: ]
2022-08-05T15:16:24.399402+00:00 app[web.1]:
2022-08-05T15:16:24.550505+00:00 heroku[web.1]: Process exited with status 1
2022-08-05T15:16:24.671364+00:00 heroku[web.1]: State changed from starting to crashed
2022-08-05T15:31:37.077623+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/session" host=cheesecake142.herokuapp.com request_id=95dbcb95-8af7-42d6-8979-10d78af79447 fwd="120.29.69.149" dyno= connect= service= status=503 bytes= protocol=https
2022-08-05T15:31:37.460979+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cheesecake142.herokuapp.com request_id=0ca459b8-538a-47f9-a4b4-296e21540db8 fwd="120.29.69.149" dyno= connect=
 service= status=503 bytes= protocol=https

I’m willing to provide additional details about this problem if needed.

Solution

So I had this exact issue myself just now, what worked for me in terms of getting rid of errors related to eventlet was specifying the python version (apparently python 3.2.0 is incompatible with the downgraded eventlet version, read eventlet issue 687). I still have other issues but they’re unrelated so this might work for you:

  • create a runtime.txt file in root directory
    • in the file add python-3.9.13

Just to clarify my package versions:

bidict==0.22.0
CacheControl==0.12.11
cachetools==5.2.0
certifi==2022.6.15
cffi==1.15.1
charset-normalizer==2.1.0
click==8.1.3
colorama==0.4.5
dnspython==1.16.0
eventlet==0.30.2
firebase-admin==5.2.0
Flask==2.2.1
Flask-SocketIO==5.2.0
gevent==21.12.0
gevent-websocket==0.10.1
google-api-core==2.8.2
google-api-python-client==2.55.0
google-auth==2.10.0
google-auth-httplib2==0.1.0
google-cloud-core==2.3.2
google-cloud-firestore==2.6.0
google-cloud-storage==2.5.0
google-crc32c==1.3.0
google-resumable-media==2.3.3
googleapis-common-protos==1.56.4
greenlet==1.1.2
grpcio==1.47.0
grpcio-status==1.47.0
gunicorn==20.1.0
httplib2==0.20.4
idna==3.3
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
msgpack==1.0.4
proto-plus==1.20.6
protobuf==3.20.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pyparsing==3.0.9
python-decouple==3.6
python-dotenv==0.20.0
python-engineio==4.3.4
python-socketio==5.7.1
requests==2.28.1
rsa==4.9
six==1.16.0
uritemplate==4.1.1
urllib3==1.26.11
Werkzeug==2.2.1
zope.event==4.5.0
zope.interface==5.4.0

My Procfile:

web: gunicorn --worker-class eventlet -w 1 application:app

Hope this works!

Edit:
Forgot to clarify that dnspython has to be 1.16.0, your error in regards to that is due to the version not being lower than 2.0.0 – i still however after downgrading that to 1.16.0 got different errors which went away with the solution above

Answered By – Rebecca

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published