Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: wrap_socket() got an unexpected keyword argument '_context' #607

Closed
ghost opened this issue Apr 6, 2020 · 3 comments
Closed

Comments

@ghost
Copy link

ghost commented Apr 6, 2020

I am using flask, socketio for a chatbot. Locally everything works fine, I can ask bot questions and I get answers. On Heroku server, I get the following Error:

[2020-04-06 09:18:35 +0000] [10] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/geventlet.py", line 99, in init_process
super().init_process()
File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
self.load_wsgi()
File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
self.wsgi = self.app.wsgi()
File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
return self.load_wsgiapp()
File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
return util.import_app(self.app_uri)
File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
mod = importlib.import_module(module)
File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/app.py", line 7, in <module>
from controllers.question_controller import model
File "/app/controllers/question_controller.py", line 12, in <module>
model = QuestionAnswerer(data, domain_name, ftp_username, ftp_password)
File "/app/.heroku/python/lib/python3.7/site-packages/socialworks_nn/question_answerer.py", line 14, in __init__
super().__init__(json_data)
File "/app/.heroku/python/lib/python3.7/site-packages/socialworks_nn/data_preprocessing/data_processing.py", line 11, in __init__
download('punkt')
File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 787, in download
for msg in self.incr_download(info_or_id, download_dir, force):
File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 636, in incr_download
info = self._info_or_id(info_or_id)
File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 609, in _info_or_id
return self.info(info_or_id)
File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 1019, in info
self._update_index()
File "/app/.heroku/python/lib/python3.7/site-packages/nltk/downloader.py", line 962, in _update_index
ElementTree.parse(urlopen(self._url)).getroot()
File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/app/.heroku/python/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/app/.heroku/python/lib/python3.7/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/app/.heroku/python/lib/python3.7/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/app/.heroku/python/lib/python3.7/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/app/.heroku/python/lib/python3.7/http/client.py", line 1026, in _send_output
self.send(msg)
File "/app/.heroku/python/lib/python3.7/http/client.py", line 966, in send
self.connect()
File "/app/.heroku/python/lib/python3.7/http/client.py", line 1422, in connect
server_hostname=server_hostname)
File "/app/.heroku/python/lib/python3.7/site-packages/eventlet/green/ssl.py", line 438, in wrap_socket
return GreenSSLSocket(sock, *a, _context=self, **kw)
File "/app/.heroku/python/lib/python3.7/site-packages/eventlet/green/ssl.py", line 76, in __new__
*args, **kw
TypeError: wrap_socket() got an unexpected keyword argument '_context'
[2020-04-06 09:18:35 +0000] [10] [INFO] Worker exiting (pid: 10)
[2020-04-06 09:18:35 +0000] [4] [INFO] Shutting down: Master
[2020-04-06 09:18:35 +0000] [4] [INFO] Reason: Worker failed to boot.

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('/chatbot')
def index():
    return render_template('index.html', async_mode=socketio.async_mode)


@socketio.on('my_event', namespace='/chatbot')
def test_message(question):
    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 my requirements.txt file:


flask==1.1.1
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

Here is my Procfile:

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

Here is my .gitlab-ci.yml file:

image: "python:3.7"
before_script:
    - apt-get update -qy
    - apt-get install -y python-dev python3-pip
    - apt-get install python-mysqldb
    - pip3 install -r requirements.txt
    - pip3 install python-socketio

production:
  script:
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
    - export $(grep -v '^#' env/development.env | xargs)
    - dpl --provider=heroku --app=socialworks --api-key=$HEROKU_SECRET_KEY
  only:
    - master

Also, my runtime.txt:
python-3.7.5

I have followed the documentation https://flask-socketio.readthedocs.io/en/latest/#gunicorn-web-server, but I have no idea why this error keeps appearing. I am new to websockets, any help will be appreciated. Maybe there is somekind of workaround this issue?

@ghost ghost closed this as completed Apr 6, 2020
@breadbored
Copy link

Did you find a solution to this?

@ghost
Copy link
Author

ghost commented Apr 20, 2020

I had to downgrade to python 3.6 because of eventlet bug.

@breadbored
Copy link

breadbored commented Apr 20, 2020

I'll try that, thank you.

EDIT: This worked for me. I had the exact same issue with Flak-SocketIO and eventlet on Heroku. I appreciate the response!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant