title: Maximum recursion depth exceeded on SSLContext (eventlet, flask, flask-socketio, tweepy)
body: <p>I'm building a flask app that displays real-time data visualizations of tweets based on a user input. Right now, the client is still hosted locally and I'm just trying to get to the point where a json of a single tweet gets emitted from the server to the client. This is also my first time building a flask app on my own, so I've been learning HTML/CSS/node.js/JS along the way (be gentle with me).</p>
  <p>My problem is with the backend/server. Here is the relevant flask code:</p>
  <pre><code>from flask import Flask, request, render_template, session
  from flask_socketio import SocketIO, emit
  from time import sleep
  import threading
  from threading import Thread, Event, Lock
  import eventlet
  import json
  import TweePoll_API_nostream
  
  eventlet.monkey_patch(socket=True)
  app = Flask(__name__)
  app.config['SECRET_KEY'] = 'secret!'
  socket = SocketIO(app, async_mode=None, logger=True, engineio_logger=True)
  streamer2 = TweePoll_API_nostream.getTweet()
  thread = None
  thread_lock = Lock()
  
  def background_thread():
      count = 0
      while True:
          socket.sleep(10)
          x = streamer2.main(v)
          count += 1
          socket.emit('my_response',
              {'data': x, 'count': count},
              namespace='/output')
  
  @app.route('/', methods = ['GET','POST'])
  def index():
      return(render_template(&quot;index.html&quot;, async_mode = socket.async_mode))
  
  @socket.on('my_event', namespace='/output')
  def test_message(message):
      global v
      v = message['data']
      print(v)
      global thread 
      with thread_lock:
          if thread is None:
              thread = socket.start_background_task(background_thread)
      emit('my_response', {'data': v, 'count': 0})
  
  if __name__ == '__main__':
      socket.run(app, port = 5000, debug = True)
  </code></pre>
  <p>The error occurs on <code>x = streamer2.main(v)</code> in the <code>background_thread()</code> function. Here is the relevant code for the tweepy streamer:</p>
  <pre><code>import tweepy
  import config
  import TweePoll_NLP_single
  import json
  
  MLObj = TweePoll_NLP_single.ReadyForSQL()
  
  class getTweet(object):
      def __init__(self):
          self.auth = tweepy.auth.OAuthHandler(config.ckey, config.csecret)
          self.auth.set_access_token(config.atoken, config.asecret)
          self.api = tweepy.API(self.auth)
  
      def main(self, keywrd):
          tweet = str()
          user = str()
          time = str()
          status = self.api.search(q = [keywrd + &quot; @realDonaldTrump&quot;, keywrd + &quot; @JoeBiden&quot;], count = 1, result_type = &quot;recent&quot;, lang = 'en')[0]
  
          if hasattr(status, &quot;retweeted_status&quot;):  # Check if Retweet
              try:
                  tweet = status.retweeted_status.extended_tweet[&quot;full_text&quot;]
              except AttributeError:
                  tweet = status.retweeted_status.text
          else:
              try:
                  tweet = status.extended_tweet[&quot;full_text&quot;]
              except AttributeError:
                  tweet = status.text
  
          user = status.author.screen_name
          time = str(status.created_at)
          prez = MLObj.whichPrez(tweet)
          clean = MLObj.kleenex(tweet)
          NRCemo = MLObj.NRCEmo(clean)
  
          printDF = json.dumps({&quot;tweet&quot;:tweet, &quot;clean&quot;:clean,
              &quot;prez&quot;:prez, &quot;NRCEmo&quot;:NRCemo, &quot;time&quot;:time, &quot;username&quot;:user})
  
          return(printDF)
  </code></pre>
  <p>This code isn't reproducible, because it connects to another file for the NLP/sentiment tagging, plus the frontend isn't included. Let me know if I need to send a link to my github or something to fix this.</p>
  <p>Here is the error output:</p>
  <pre><code>Exception in thread Thread-6:
  Traceback (most recent call last):
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\tweepy\binder.py&quot;, line 183, in execute
      resp = self.session.request(self.method,
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py&quot;, line 530, in request
      resp = self.send(prep, **send_kwargs)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py&quot;, line 643, in send
      r = adapter.send(request, **kwargs)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py&quot;, line 439, in send
      resp = conn.urlopen(
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py&quot;, line 670, in urlopen
      httplib_response = self._make_request(
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py&quot;, line 381, in _make_request
      self._validate_conn(conn)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py&quot;, line 976, in _validate_conn
      conn.connect()
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py&quot;, line 342, in connect
      self.ssl_context = create_urllib3_context(
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py&quot;, line 276, in create_urllib3_context
      context.options |= options
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 602, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 602, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 602, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    [Previous line repeated 481 more times]
  RecursionError: maximum recursion depth exceeded
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\threading.py&quot;, line 932, in _bootstrap_inner
      self.run()
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\threading.py&quot;, line 870, in run
      self._target(*self._args, **self._kwargs)
    File &quot;C:\Users\swagj\Documents\GitHub\TweePoll\TweePoll_Server_V2.py&quot;, line 28, in background_thread
      x = streamer2.main(v)
    File &quot;C:\Users\swagj\Documents\GitHub\TweePoll\TweePoll_API_nostream.py&quot;, line 21, in main
      status = self.api.search(q = [keywrd + &quot; @realDonaldTrump&quot;, keywrd + &quot; @JoeBiden&quot;], count = 1, result_type = &quot;recent&quot;, lang = 'en')[0]
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\tweepy\binder.py&quot;, line 250, in _call
      return method.execute()
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\tweepy\binder.py&quot;, line 191, in execute
      six.reraise(TweepError, TweepError('Failed to send request: %s' % e), sys.exc_info()[2])
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\six.py&quot;, line 702, in reraise
      raise value.with_traceback(tb)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\tweepy\binder.py&quot;, line 183, in execute
      resp = self.session.request(self.method,
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py&quot;, line 530, in request
      resp = self.send(prep, **send_kwargs)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py&quot;, line 643, in send
      r = adapter.send(request, **kwargs)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py&quot;, line 439, in send
      resp = conn.urlopen(
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py&quot;, line 670, in urlopen
      httplib_response = self._make_request(
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py&quot;, line 381, in _make_request
      self._validate_conn(conn)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py&quot;, line 976, in _validate_conn
      conn.connect()
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py&quot;, line 342, in connect
      self.ssl_context = create_urllib3_context(
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py&quot;, line 276, in create_urllib3_context
      context.options |= options
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 602, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 602, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    File &quot;C:\Users\swagj\AppData\Local\Programs\Python\Python38\lib\ssl.py&quot;, line 602, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    [Previous line repeated 481 more times]
  tweepy.error.TweepError: Failed to send request: maximum recursion depth exceeded
  </code></pre>
  <p>Final dump, here is my info:</p>
  <pre><code>Windows 10
  python = 3.8.3
  eventlet = 0.25.2
  tweepy = 3.8.0
  websocket-client = 0.57.0
  websockets = 8.1
  Flask = 1.1.2
  Flask-SocketIO = 4.3.0
  </code></pre>
  <p>I have no idea why this doesn't work, but I have a feeling it has to do with eventlet. Any clues? Happy to give more info if needed :)</p>