Flask-socketio: Chatbot no response on Heroku server

Created on 6 Apr 2020  路  5Comments  路  Source: miguelgrinberg/Flask-SocketIO

I am running my flask socketio application for a chatbot. Locally everything works fine, I can ask questions and get answers. But on the Heroku server I can ask questions, but I do not receive any response.

Here is the code where I run my server:

from flask import Flask, render_template, session
from models import db
from flask_restful import Api
from flask_socketio import SocketIO, emit
from controllers.image_controller import ImageController
from controllers.question_controller import model

app = Flask(__name__)
app.config.from_object("config.Config")
app.config['SECRET_KEY'] = '123456'
db.init_app(app)
socketio = SocketIO(app)
api = Api(app)

api.add_resource(ImageController, '/images')


@app.route('/')
def test():
    return "Test"


@app.route('/chatbot')
def index():
    return render_template('index.html', async_mode=socketio.async_mode)


@socketio.on('my_event', namespace='/chatbot')
def test_message(question):
    print("testing_sockets")
    answer = model.get_answer(question['data'])
    session['receive_count'] = session.get('receive_count', 0) + 1
    emit('my_response', {'data': answer, 'count': session['receive_count']})


if __name__ == '__main__':
    socketio.run(app, debug=True, use_reloader=False)

Here is the index.html for the chatbot:

<!DOCTYPE HTML>
<html>
<head>
    <title>Flask-SocketIO Test</title>
    <script src="//code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
    <script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            // Use a "/test" namespace.
            // An application can open a connection on multiple namespaces, and
            // Socket.IO will multiplex all those connections on a single
            // physical channel. If you don't care about multiple channels, you
            // can set the namespace to an empty string.
            namespace = '/chatbot';

            // Connect to the Socket.IO server.
            // The connection URL has the following format, relative to the current page:
            //     http[s]://<domain>:<port>[/<namespace>]
            var socket = io(namespace, {transports: ['websocket']});

            // Event handler for server sent data.
            // The callback function is invoked whenever the server emits data
            // to the client. The data is then displayed in the "Received"
            // section of the page.
            socket.on('my_response', function(msg, cb) {
                $('#log').append('<br>' + $('<div/>').text('Bot: ' + msg.data).html());
                if (cb)
                    cb();
            });


            // Handlers for the different forms in the page.
            // These accept data from the user and send it to the server in a
            // variety of ways
            $('form#emit').submit(function(event) {
                $('#log').append('<br>' + $('<div/>').text('You: ' + $('#emit_data').val()).html());
                socket.emit('my_event', {data: $('#emit_data').val()});
                $('#emit_data').val("").focus()
                return false;
            });
        });
    </script>
</head>
<body>
    <h2>Chat:</h2>
    <div id="log"></div>
    <form id="emit" method="POST" action='#'>
        <input type="text" name="emit_data" id="emit_data" placeholder="Type message">
        <input type="submit" value="Send">
    </form>
</body>
</html>

Here are the Heroku logs:

2020-04-06T16:13:38.897393+00:00 heroku[web.1]: Restarting
2020-04-06T16:13:39.194170+00:00 heroku[web.1]: State changed from up to starting
2020-04-06T16:13:40.764736+00:00 app[web.1]: [2020-04-06 16:13:40 +0000] [4] [INFO] Handling signal: term
2020-04-06T16:13:41.268073+00:00 app[web.1]: [2020-04-06 16:13:41 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-04-06T16:13:42.075108+00:00 app[web.1]: [2020-04-06 16:13:42 +0000] [4] [INFO] Shutting down: Master
2020-04-06T16:14:01.477523+00:00 heroku[web.1]: State changed from starting to up
2020-04-06T16:14:01.170053+00:00 app[web.1]: [2020-04-06 16:14:01 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-04-06T16:14:01.170625+00:00 app[web.1]: [2020-04-06 16:14:01 +0000] [4] [INFO] Listening at: http://0.0.0.0:37029 (4)
2020-04-06T16:14:01.170718+00:00 app[web.1]: [2020-04-06 16:14:01 +0000] [4] [INFO] Using worker: geventwebsocket.gunicorn.workers.GeventWebSocketWorker
2020-04-06T16:14:01.175272+00:00 app[web.1]: [2020-04-06 16:14:01 +0000] [10] [INFO] Booting worker with pid: 10
2020-04-06T16:14:03.925778+00:00 app[web.1]: [nltk_data] Downloading package punkt to
2020-04-06T16:14:03.925788+00:00 app[web.1]: [nltk_data]     /app/.heroku/python/nltk_data...
2020-04-06T16:14:04.143302+00:00 app[web.1]: [nltk_data]   Unzipping tokenizers/punkt.zip.
2020-04-06T16:14:04.760270+00:00 app[web.1]: *cmd* 'CWD /public_html'
2020-04-06T16:14:04.760280+00:00 app[web.1]: *put* 'CWD /public_html\r\n'
2020-04-06T16:14:04.803913+00:00 app[web.1]: *get* '250 OK. Current directory is /public_html\n'
2020-04-06T16:14:04.803931+00:00 app[web.1]: *resp* '250 OK. Current directory is /public_html'
2020-04-06T16:14:04.804029+00:00 app[web.1]: *cmd* 'TYPE I'
2020-04-06T16:14:04.804048+00:00 app[web.1]: *put* 'TYPE I\r\n'
2020-04-06T16:14:04.847645+00:00 app[web.1]: *get* '200 TYPE is now 8-bit binary\n'
2020-04-06T16:14:04.847647+00:00 app[web.1]: *resp* '200 TYPE is now 8-bit binary'
2020-04-06T16:14:04.847682+00:00 app[web.1]: *cmd* 'PASV'
2020-04-06T16:14:04.847703+00:00 app[web.1]: *put* 'PASV\r\n'
2020-04-06T16:14:04.891387+00:00 app[web.1]: *get* '227 Entering Passive Mode (79,98,25,30,243,50)\n'
2020-04-06T16:14:04.891390+00:00 app[web.1]: *resp* '227 Entering Passive Mode (79,98,25,30,243,50)'
2020-04-06T16:14:04.935445+00:00 app[web.1]: *cmd* 'RETR 2020-04-02-model.h5'
2020-04-06T16:14:04.935450+00:00 app[web.1]: *put* 'RETR 2020-04-02-model.h5\r\n'
2020-04-06T16:14:04.979285+00:00 app[web.1]: *get* '150-Accepted data connection\n'
2020-04-06T16:14:04.979395+00:00 app[web.1]: *get* '150 393.8 kbytes to download\n'
2020-04-06T16:14:04.979484+00:00 app[web.1]: *resp* '150-Accepted data connection\n150 393.8 kbytes to download'
2020-04-06T16:14:05.195036+00:00 app[web.1]: *get* '226-File successfully transferred\n'
2020-04-06T16:14:05.195076+00:00 app[web.1]: *get* '226 0.216 seconds (measured here), 1.78 Mbytes per second\n'
2020-04-06T16:14:05.195096+00:00 app[web.1]: *resp* '226-File successfully transferred\n226 0.216 seconds (measured here), 1.78 Mbytes per second'
2020-04-06T16:14:05.195100+00:00 app[web.1]: *cmd* 'QUIT'
2020-04-06T16:14:05.195120+00:00 app[web.1]: *put* 'QUIT\r\n'
2020-04-06T16:14:05.238604+00:00 app[web.1]: *get* '221-Goodbye. You uploaded 0 and downloaded 394 kbytes.\n'
2020-04-06T16:14:05.238623+00:00 app[web.1]: *get* '221 Logout.\n'
2020-04-06T16:14:05.238643+00:00 app[web.1]: *resp* '221-Goodbye. You uploaded 0 and downloaded 394 kbytes.\n221 Logout.'
2020-04-06T16:14:05.256607+00:00 app[web.1]: 2020-04-06 16:14:05.256548: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2500050000 Hz
2020-04-06T16:14:05.258492+00:00 app[web.1]: 2020-04-06 16:14:05.258442: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x558746488110 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-04-06T16:14:05.258496+00:00 app[web.1]: 2020-04-06 16:14:05.258477: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-04-06T16:14:25.000000+00:00 app[api]: Build succeeded
2020-04-06T16:15:44.572338+00:00 heroku[router]: at=info method=GET path="/" host=socialworks.herokuapp.com request_id=39c79a11-da1c-42ac-a0f3-f1bfadc50fbc fwd="88.223.107.136" dyno=web.1 connect=1ms service=4ms status=200 bytes=126 protocol=https
2020-04-06T16:15:51.206657+00:00 heroku[router]: at=info method=GET path="/chatbot" host=socialworks.herokuapp.com request_id=f587ea46-9842-41e9-8e37-ce882ff21e13 fwd="88.223.107.136" dyno=web.1 connect=0ms service=7ms status=200 bytes=2477 protocol=https
2020-04-06T16:15:51.400095+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=socialworks.herokuapp.com request_id=ed7af551-725c-49ac-96e7-dcfd9174df73 fwd="88.223.107.136" dyno=web.1 connect=0ms service=2ms status=404 bytes=356 protocol=https
2020-04-06T16:15:51.506165+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket" host=socialworks.herokuapp.com request_id=07c9ab9f-7a92-4c81-b104-d9c5a101b385 fwd="88.223.107.136" dyno=web.1 connect=1ms service=2ms status=101 bytes=129 protocol=https
2020-04-06T16:16:12.549631+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket" host=socialworks.herokuapp.com request_id=e8c1335c-b3d0-4259-96fc-7c3b2a60c86e fwd="88.223.107.136" dyno=web.1 connect=0ms service=1ms status=101 bytes=129 protocol=https
2020-04-06T16:16:35.101462+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket" host=socialworks.herokuapp.com request_id=649d2235-ecfb-45f6-b34f-0145fa26aea6 fwd="88.223.107.136" dyno=web.1 connect=0ms service=2ms status=101 bytes=129 protocol=https

Here is my Procfile:
web: gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app

I am not receiving any errors on the browsers console. And I am not sure why I am not receiving any answers from the chat bot when locally everything works perfect. I am new to websockets, any help will be appreciated.

question

All 5 comments

You need to enable Socket.IO logs to have more information on the state of the Socket.IO server:

socketio = SocketIO(app, logger=True, engineio_logger=True)

I have added socketio = SocketIO(app, logger=True, engineio_logger=True)
Here is what I can see when running the code locally:

*cmd* 'CWD /public_html'
*put* 'CWD /public_html\r\n'
*get* '250 OK. Current directory is /public_html\n'
*resp* '250 OK. Current directory is /public_html'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 TYPE is now 8-bit binary\n'
*resp* '200 TYPE is now 8-bit binary'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (79,98,25,30,203,112)\n'
*resp* '227 Entering Passive Mode (79,98,25,30,203,112)'
*cmd* 'RETR 2020-04-02-model.h5'
*put* 'RETR 2020-04-02-model.h5\r\n'
*get* '150-Accepted data connection\n'
*get* '150 393.8 kbytes to download\n'
*resp* '150-Accepted data connection\n150 393.8 kbytes to download'
*get* '226-File successfully transferred\n'
*get* '226 0.071 seconds (measured here), 5.41 Mbytes per second\n'
*resp* '226-File successfully transferred\n226 0.071 seconds (measured here), 5.41 Mbytes per second'
*cmd* 'QUIT'
*put* 'QUIT\r\n'
*get* '221-Goodbye. You uploaded 0 and downloaded 394 kbytes.\n'
*get* '221 Logout.\n'
*resp* '221-Goodbye. You uploaded 0 and downloaded 394 kbytes.\n221 Logout.'
2020-04-06 20:45:19.365478: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-04-06 20:45:19.391120: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2394480000 Hz
2020-04-06 20:45:19.391428: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4585750 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-04-06 20:45:19.391455: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Server initialized for eventlet.
(30420) wsgi starting up on http://127.0.0.1:5000
(30420) accepted ('127.0.0.1', 59734)
bbf75b9d33294f51a6a8bc4f439da972: Sending packet OPEN data {'sid': 'bbf75b9d33294f51a6a8bc4f439da972', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
bbf75b9d33294f51a6a8bc4f439da972: Sending packet MESSAGE data 0
bbf75b9d33294f51a6a8bc4f439da972: Received request to upgrade to websocket
bbf75b9d33294f51a6a8bc4f439da972: Upgrade to websocket successful
bbf75b9d33294f51a6a8bc4f439da972: Received packet MESSAGE data 0/chatbot,
bbf75b9d33294f51a6a8bc4f439da972: Sending packet MESSAGE data 0/chatbot
(30420) accepted ('127.0.0.1', 59736)
127.0.0.1 - - [06/Apr/2020 20:45:23] "GET / HTTP/1.1" 200 150 0.001111
127.0.0.1 - - [06/Apr/2020 20:45:26] "GET /chatbot HTTP/1.1" 200 2501 0.003330
(30420) accepted ('127.0.0.1', 59742)
58403604617e4e8282e7c13cacab7076: Sending packet OPEN data {'sid': '58403604617e4e8282e7c13cacab7076', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
58403604617e4e8282e7c13cacab7076: Sending packet MESSAGE data 0
58403604617e4e8282e7c13cacab7076: Received request to upgrade to websocket
58403604617e4e8282e7c13cacab7076: Upgrade to websocket successful
58403604617e4e8282e7c13cacab7076: Received packet MESSAGE data 0/chatbot,
58403604617e4e8282e7c13cacab7076: Sending packet MESSAGE data 0/chatbot
testing_sockets
58403604617e4e8282e7c13cacab7076: Received packet MESSAGE data 2/chatbot,["my_event",{"data":"hi!"}]
received event "my_event" from 58403604617e4e8282e7c13cacab7076 [/chatbot]
emitting event "my_response" to 58403604617e4e8282e7c13cacab7076 [/chatbot]
58403604617e4e8282e7c13cacab7076: Sending packet MESSAGE data 2/chatbot,["my_response",{"data":"Hi there, how can I help?","count":1}]
bbf75b9d33294f51a6a8bc4f439da972: Received packet PING data None
bbf75b9d33294f51a6a8bc4f439da972: Sending packet PONG data None

Here are the Heroku logs:

2020-04-06T17:41:17.628681+00:00 heroku[web.1]: State changed from down to starting
2020-04-06T17:41:35.953605+00:00 heroku[web.1]: State changed from starting to up
2020-04-06T17:41:35.917416+00:00 app[web.1]: [2020-04-06 17:41:35 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-04-06T17:41:35.917949+00:00 app[web.1]: [2020-04-06 17:41:35 +0000] [4] [INFO] Listening at: http://0.0.0.0:33680 (4)
2020-04-06T17:41:35.918045+00:00 app[web.1]: [2020-04-06 17:41:35 +0000] [4] [INFO] Using worker: geventwebsocket.gunicorn.workers.GeventWebSocketWorker
2020-04-06T17:41:35.922880+00:00 app[web.1]: [2020-04-06 17:41:35 +0000] [10] [INFO] Booting worker with pid: 10
2020-04-06T17:41:39.225645+00:00 app[web.1]: [nltk_data] Downloading package punkt to
2020-04-06T17:41:39.225654+00:00 app[web.1]: [nltk_data]     /app/.heroku/python/nltk_data...
2020-04-06T17:41:39.570859+00:00 app[web.1]: [nltk_data]   Unzipping tokenizers/punkt.zip.
2020-04-06T17:41:40.192452+00:00 app[web.1]: *cmd* 'CWD /public_html'
2020-04-06T17:41:40.192465+00:00 app[web.1]: *put* 'CWD /public_html\r\n'
2020-04-06T17:41:40.235069+00:00 app[web.1]: *get* '250 OK. Current directory is /public_html\n'
2020-04-06T17:41:40.235106+00:00 app[web.1]: *resp* '250 OK. Current directory is /public_html'
2020-04-06T17:41:40.235255+00:00 app[web.1]: *cmd* 'TYPE I'
2020-04-06T17:41:40.235303+00:00 app[web.1]: *put* 'TYPE I\r\n'
2020-04-06T17:41:40.277812+00:00 app[web.1]: *get* '200 TYPE is now 8-bit binary\n'
2020-04-06T17:41:40.277848+00:00 app[web.1]: *resp* '200 TYPE is now 8-bit binary'
2020-04-06T17:41:40.277895+00:00 app[web.1]: *cmd* 'PASV'
2020-04-06T17:41:40.277934+00:00 app[web.1]: *put* 'PASV\r\n'
2020-04-06T17:41:40.320330+00:00 app[web.1]: *get* '227 Entering Passive Mode (79,98,25,30,50,103)\n'
2020-04-06T17:41:40.320359+00:00 app[web.1]: *resp* '227 Entering Passive Mode (79,98,25,30,50,103)'
2020-04-06T17:41:40.365351+00:00 app[web.1]: *cmd* 'RETR 2020-04-02-model.h5'
2020-04-06T17:41:40.365353+00:00 app[web.1]: *put* 'RETR 2020-04-02-model.h5\r\n'
2020-04-06T17:41:40.410059+00:00 app[web.1]: *get* '150-Accepted data connection\n'
2020-04-06T17:41:40.410111+00:00 app[web.1]: *get* '150-The computer is your friend. Trust the computer\n'
2020-04-06T17:41:40.410169+00:00 app[web.1]: *get* '150 393.8 kbytes to download\n'
2020-04-06T17:41:40.410259+00:00 app[web.1]: *resp* '150-Accepted data connection\n150-The computer is your friend. Trust the computer\n150 393.8 kbytes to download'
2020-04-06T17:41:40.632502+00:00 app[web.1]: *get* '226-File successfully transferred\n'
2020-04-06T17:41:40.632518+00:00 app[web.1]: *get* '226 0.223 seconds (measured here), 1.73 Mbytes per second\n'
2020-04-06T17:41:40.632554+00:00 app[web.1]: *resp* '226-File successfully transferred\n226 0.223 seconds (measured here), 1.73 Mbytes per second'
2020-04-06T17:41:40.632643+00:00 app[web.1]: *cmd* 'QUIT'
2020-04-06T17:41:40.632691+00:00 app[web.1]: *put* 'QUIT\r\n'
2020-04-06T17:41:40.675268+00:00 app[web.1]: *get* '221-Goodbye. You uploaded 0 and downloaded 394 kbytes.\n'
2020-04-06T17:41:40.675332+00:00 app[web.1]: *get* '221 Logout.\n'
2020-04-06T17:41:40.675379+00:00 app[web.1]: *resp* '221-Goodbye. You uploaded 0 and downloaded 394 kbytes.\n221 Logout.'
2020-04-06T17:41:40.693412+00:00 app[web.1]: 2020-04-06 17:41:40.693345: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2500070000 Hz
2020-04-06T17:41:40.695343+00:00 app[web.1]: 2020-04-06 17:41:40.695296: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55b5df6b1c20 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-04-06T17:41:40.695369+00:00 app[web.1]: 2020-04-06 17:41:40.695333: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-04-06T17:41:42.118681+00:00 app[web.1]: Server initialized for eventlet.
2020-04-06T17:41:59.000000+00:00 app[api]: Build succeeded
2020-04-06T17:42:55.417681+00:00 heroku[router]: at=info method=GET path="/" host=socialworks.herokuapp.com request_id=9297f454-253b-423d-a27a-ad961f72b452 fwd="88.223.107.136" dyno=web.1 connect=0ms service=2ms status=200 bytes=126 protocol=https
2020-04-06T17:42:58.287493+00:00 heroku[router]: at=info method=GET path="/chatbot" host=socialworks.herokuapp.com request_id=96fc0150-d9c0-4d41-948a-5ec184043362 fwd="88.223.107.136" dyno=web.1 connect=0ms service=13ms status=200 bytes=2477 protocol=https
2020-04-06T17:42:58.570472+00:00 app[web.1]: https://socialworks.herokuapp.com is not an accepted origin.
2020-04-06T17:42:58.571904+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket" host=socialworks.herokuapp.com request_id=d75e3a7e-4c3f-4452-843d-6403ccbb9a25 fwd="88.223.107.136" dyno=web.1 connect=1ms service=3ms status=101 bytes=129 protocol=https

It still works locally, but it does not on Heroku server.

The 'is not an accepted issue' dissapeared when I addded cors_allowed_origins='*' to SocketIO().
Unfortunately, this was the easy part as I can see.
After that I was receiving an error:RuntimeError: You need to use the eventlet server. See the Deployment section of the documentation for more information.
Because of that I have changed my Procfile
from
web: gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
to
gunicorn --worker-class eventlet -w 1 app:app
And now I am receiving the following Error and my Heroku server does not work anymore:

2020-04-06T20:19:11.542762+00:00 app[web.1]: [2020-04-06 20:19:11 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-04-06T20:19:11.543684+00:00 app[web.1]: [2020-04-06 20:19:11 +0000] [4] [INFO] Listening at: http://0.0.0.0:16383 (4)
2020-04-06T20:19:11.543845+00:00 app[web.1]: [2020-04-06 20:19:11 +0000] [4] [INFO] Using worker: eventlet
2020-04-06T20:19:11.550757+00:00 app[web.1]: [2020-04-06 20:19:11 +0000] [10] [INFO] Booting worker with pid: 10
2020-04-06T20:19:12.792059+00:00 heroku[web.1]: State changed from starting to up
2020-04-06T20:19:14.835676+00:00 heroku[web.1]: State changed from up to crashed
2020-04-06T20:19:14.425472+00:00 app[web.1]: [2020-04-06 20:19:14 +0000] [10] [ERROR] Exception in worker process
2020-04-06T20:19:14.425502+00:00 app[web.1]: Traceback (most recent call last):
2020-04-06T20:19:14.425503+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-04-06T20:19:14.425504+00:00 app[web.1]: worker.init_process()
2020-04-06T20:19:14.425505+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/geventlet.py", line 99, in init_process
2020-04-06T20:19:14.425505+00:00 app[web.1]: super().init_process()
2020-04-06T20:19:14.425506+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-04-06T20:19:14.425506+00:00 app[web.1]: self.load_wsgi()
2020-04-06T20:19:14.425506+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-04-06T20:19:14.425507+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-04-06T20:19:14.425507+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-04-06T20:19:14.425508+00:00 app[web.1]: self.callable = self.load()
2020-04-06T20:19:14.425508+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-04-06T20:19:14.425508+00:00 app[web.1]: return self.load_wsgiapp()
2020-04-06T20:19:14.425509+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-04-06T20:19:14.425509+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-04-06T20:19:14.425509+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
2020-04-06T20:19:14.425510+00:00 app[web.1]: mod = importlib.import_module(module)
2020-04-06T20:19:14.425510+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
2020-04-06T20:19:14.425511+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-04-06T20:19:14.425511+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
2020-04-06T20:19:14.425511+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
2020-04-06T20:19:14.425512+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
2020-04-06T20:19:14.425512+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
2020-04-06T20:19:14.425512+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 728, in exec_module
2020-04-06T20:19:14.425513+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-04-06T20:19:14.425513+00:00 app[web.1]: File "/app/app.py", line 7, in <module>
2020-04-06T20:19:14.425513+00:00 app[web.1]: from controllers.question_controller import model
2020-04-06T20:19:14.425514+00:00 app[web.1]: File "/app/controllers/question_controller.py", line 12, in <module>
2020-04-06T20:19:14.425514+00:00 app[web.1]: model = QuestionAnswerer(data, domain_name, ftp_username, ftp_password)
2020-04-06T20:19:14.425514+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/socialworks_nn/question_answerer.py", line 14, in __init__
2020-04-06T20:19:14.425515+00:00 app[web.1]: super().__init__(json_data)
2020-04-06T20:19:14.425516+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/socialworks_nn/data_preprocessing/data_processing.py", line 11, in __init__
2020-04-06T20:19:14.425516+00:00 app[web.1]: download('punkt')
2020-04-06T20:19:14.425516+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 787, in download
2020-04-06T20:19:14.425517+00:00 app[web.1]: for msg in self.incr_download(info_or_id, download_dir, force):
2020-04-06T20:19:14.425517+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 636, in incr_download
2020-04-06T20:19:14.425517+00:00 app[web.1]: info = self._info_or_id(info_or_id)
2020-04-06T20:19:14.425518+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 609, in _info_or_id
2020-04-06T20:19:14.425518+00:00 app[web.1]: return self.info(info_or_id)
2020-04-06T20:19:14.425518+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 1019, in info
2020-04-06T20:19:14.425519+00:00 app[web.1]: self._update_index()
2020-04-06T20:19:14.425519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 962, in _update_index
2020-04-06T20:19:14.425519+00:00 app[web.1]: ElementTree.parse(urlopen(self._url)).getroot()
2020-04-06T20:19:14.425520+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 222, in urlopen
2020-04-06T20:19:14.425520+00:00 app[web.1]: return opener.open(url, data, timeout)
2020-04-06T20:19:14.425520+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 525, in open
2020-04-06T20:19:14.425520+00:00 app[web.1]: response = self._open(req, data)
2020-04-06T20:19:14.425521+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 543, in _open
2020-04-06T20:19:14.425521+00:00 app[web.1]: '_open', req)
2020-04-06T20:19:14.425521+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 503, in _call_chain
2020-04-06T20:19:14.425522+00:00 app[web.1]: result = func(*args)
2020-04-06T20:19:14.425522+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 1360, in https_open
2020-04-06T20:19:14.425522+00:00 app[web.1]: context=self._context, check_hostname=self._check_hostname)
2020-04-06T20:19:14.425523+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 1317, in do_open
2020-04-06T20:19:14.425523+00:00 app[web.1]: encode_chunked=req.has_header('Transfer-encoding'))
2020-04-06T20:19:14.425523+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1252, in request
2020-04-06T20:19:14.425524+00:00 app[web.1]: self._send_request(method, url, body, headers, encode_chunked)
2020-04-06T20:19:14.425524+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1298, in _send_request
2020-04-06T20:19:14.425524+00:00 app[web.1]: self.endheaders(body, encode_chunked=encode_chunked)
2020-04-06T20:19:14.425531+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1247, in endheaders
2020-04-06T20:19:14.425532+00:00 app[web.1]: self._send_output(message_body, encode_chunked=encode_chunked)
2020-04-06T20:19:14.425532+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1026, in _send_output
2020-04-06T20:19:14.425533+00:00 app[web.1]: self.send(msg)
2020-04-06T20:19:14.425533+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 966, in send
2020-04-06T20:19:14.425533+00:00 app[web.1]: self.connect()
2020-04-06T20:19:14.425534+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1422, in connect
2020-04-06T20:19:14.425534+00:00 app[web.1]: server_hostname=server_hostname)
2020-04-06T20:19:14.425534+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/eventlet/green/ssl.py", line 438, in wrap_socket
2020-04-06T20:19:14.425534+00:00 app[web.1]: return GreenSSLSocket(sock, *a, _context=self, **kw)
2020-04-06T20:19:14.425535+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/eventlet/green/ssl.py", line 76, in __new__
2020-04-06T20:19:14.425535+00:00 app[web.1]: *args, **kw
2020-04-06T20:19:14.425536+00:00 app[web.1]: TypeError: wrap_socket() got an unexpected keyword argument '_context'
2020-04-06T20:19:14.425884+00:00 app[web.1]: [2020-04-06 20:19:14 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-04-06T20:19:14.741045+00:00 app[web.1]: [2020-04-06 20:19:14 +0000] [4] [INFO] Shutting down: Master
2020-04-06T20:19:14.741153+00:00 app[web.1]: [2020-04-06 20:19:14 +0000] [4] [INFO] Reason: Worker failed to boot.
2020-04-06T20:19:17.000000+00:00 app[api]: Build succeeded
2020-04-06T20:19:19.854416+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/socket.io/?EIO=3&transport=websocket" host=socialworks.herokuapp.com request_id=512c3018-a048-42c2-8341-068e527b9d5c fwd="88.223.107.136" dyno=web.1 connect=5000ms service= status=503 bytes= protocol=https
2020-04-06T20:19:23.811368+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/socket.io/?EIO=3&transport=websocket" host=socialworks.herokuapp.com request_id=7f2be3b6-ddcc-4b47-af85-9cdd05f1667b fwd="88.223.107.136" dyno= connect= service= status=503 bytes= protocol=https
2020-04-06T20:19:28.986081+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/socket.io/?EIO=3&transport=websocket" host=socialworks.herokuapp.com request_id=1a271589-74ba-4721-82c6-83a1fa84805a fwd="88.223.107.136" dyno= connect= service= status=503 bytes= protocol=https
2020-04-06T20:19:34.155230+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/socket.io/?EIO=3&transport=websocket" host=socialworks.herokuapp.com request_id=e996e041-8deb-4676-82a0-8b5fda0cddf9 fwd="88.223.107.136" dyno= connect= service= status=503 bytes= protocol=https

I have read a lot about this error: TypeError: wrap_socket() got an unexpected keyword argument '_context'

I have added pyopenssl requirement but it did not help. (I saw somewhere that this requirement would solve the issue).

Here is my requirement.txt file:

flask==1.1.2
flask_sqlalchemy==2.4.1
gunicorn==20.0.4
jinja2==2.11.1
mysqlclient==1.4.6
Flask_SocketIO==4.2.1
flask_restful==0.3.8
python-engineio==3.12.1
python-socketio==4.4.0
eventlet==0.25.1
python-dotenv==0.12.0
h5py==2.10.0
setuptools==46.0.0
greenlet==0.4.15
pyopenssl==19.1.0
gevent-websocket

Thank you for helping me with this issue. I have read a lot about this error message and I have no idea how to solve it, I tried running my application on Python 3.6 and Python 3.8, neither of those helped. Therefore I do not have a clue on how to solve this issue.

First of all, for the first issue, regarding origins, do not set the allowed origins variable to '*'. Better to be specific, use cors_allowed_origins='https://socialworks.herokuapp.com'. No need to allow every possible client in the planet. Security is important.

The issue that you are having is a bug in eventlet that is still open and does not have a fix available. What you can try is downgrade eventlet to older versions until you find one that works. Alternatively, you can also replace eventlet with gevent and gevent-websocket. Other than that, I'm not sure what else you can do other than wait for the bug to be fixed.

Thank you for the advice about cord_allowed_origins, I will look into that. I have tried again running my app on Python 3.6 and now everything works! Thank you for your help, Miguel!

Was this page helpful?
0 / 5 - 0 ratings