title: Python - NameError: name 'PROTOCOL_SSLv3' is not defined, when using gevent
body: <p>So I had a Flask app on one machine in a virtualenv (raspberry pi running raspbian) and everything worked just fine, however when I ported it to another raspberry pi, also running raspbian, and set up a new virtualenv to the exact same specifications, running the app throws this:</p>
  
  <p>The Flask app is a socket-io chat app, that uses ajax and stuff.</p>
  
  <pre><code>Traceback (most recent call last):
  File "application.py", line 10, in &lt;module&gt;
  from flask.ext.socketio import SocketIO, emit
  File "/home/host/chat-server/venv/local/lib/python2.7/site-packages/flask/exthook.py", line 62, in load_module
  __import__(realname)
  File "/home/host/chat-server/venv/local/lib/python2.7/site-packages/flask_socketio/__init__.py", line 2, in &lt;module&gt;
  monkey.patch_all()
  File "/home/host/chat-server/venv/local/lib/python2.7/site-packages/gevent/monkey.py", line 185, in patch_all
  patch_socket(dns=dns, aggressive=aggressive)
  File "/home/host/chat-server/venv/local/lib/python2.7/site-packages/gevent/monkey.py", line 124, in patch_socket
  from gevent import socket
  File "/home/host/chat-server/venv/local/lib/python2.7/site-packages/gevent/socket.py", line 659, in &lt;module&gt;
  from gevent.ssl import sslwrap_simple as ssl, SSLError as sslerror, SSLSocket as SSLType
  File "/home/host/chat-server/venv/local/lib/python2.7/site-packages/gevent/ssl.py", line 386, in &lt;module&gt;
  def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None):
  NameError: name 'PROTOCOL_SSLv3' is not defined
  Exception KeyError: KeyError(3061183472L,) in &lt;module 'threading' from '/usr/lib/python2.7/threading.pyc'&gt; ignored
  </code></pre>
  
  <p>The process of setting up the venv was as follows,</p>
  
  <pre><code>virtualenv venv
  source venv/bin/activate
  pip install -r requirements.txt
  </code></pre>
  
  <p>requirements.txt looks like,</p>
  
  <pre><code>Flask==0.10.1
  Flask-SocketIO==0.3.7
  Jinja2==2.7.2
  MarkupSafe==0.23
  Werkzeug==0.9.4
  gevent==1.0.1
  gevent-socketio==0.3.6
  gevent-websocket==0.9.3
  greenlet==0.4.2
  ipython==2.1.0
  itsdangerous==0.24
  pyreadline==2.0
  </code></pre>
  
  <p>and when running <code>venv/bin/pip freeze</code>, both machines give the exact same packages and versions.</p>
  
  <p>BTW, my application.py is as follows, although I don't think it's part of the problem, since it works fine on my first machine (yes, I know it's sloppy, but it was an experiment).</p>
  
  <pre><code>from flask.ext.socketio import SocketIO, emit
  from flask import Flask, render_template, url_for, copy_current_request_context, request, session, redirect
  from random import random
  from time import sleep
  import json, pickle, os, binascii, pickler
  
  app = Flask(__name__)
  app.config['SECRET_KEY'] = binascii.b2a_hex(os.urandom(16))
  app.config['DEBUG'] = True
  app.config['PICKLE_RESET'] = "KGxwMAou"
  app.config['BAD_NAMES'] = ["wg4568"]
  app.config['SECRET_PASSWORD'] = "thepassword"
  
  #turn the flask app into a socketio app
  socketio = SocketIO(app)
  
  class Reciever():
      def __init__(self):
          self.messages = pickler.load("messages")
  
      def send(self, user, message):
          if len(message):
              self.messages.insert(0, (user, message))
              pickler.save(self.messages, "messages")
              socketio.emit('newmsg', {'content': message, 'user': user}, namespace='/msg')
              return "Sent from " + user + " that reads, " + message
          else:
              return "Message was blank, not sent"
  
      def render(self):
  #        if not session["VIEW"]:
  #            return '&lt;p id="alert"&gt;&lt;strong&gt;' + self.messages[0][0] + ': &lt;/strong&gt;' + self.messages[0][1] + '&lt;/p&gt;'
  #        else:
      if 1:
              html = ""
              for msg in self.messages[:session["VIEW"]]:
                  if msg[0] == "ALERT":
                      html += '&lt;p id="alert"&gt;&lt;strong&gt;' + msg[0] + ': &lt;/strong&gt;' + msg[1] + '&lt;/p&gt;'
                  else:
                      html += '&lt;p&gt;&lt;strong&gt;' + msg[0] + ': &lt;/strong&gt;' + msg[1] + '&lt;/p&gt;'
              return html
  
  rec = Reciever()
  
  @app.before_request
  def before_request():
      try: session["VIEW"]
      except KeyError: session["VIEW"] = 0
      try: session["USERNAME"]
      except KeyError: session["USERNAME"] = "AnonUser-" + binascii.b2a_hex(os.urandom(4))
  #    if not request.url.split("/")[-1:][0] == "send":
  #        rec.send("ALERT", session["USERNAME"] + " has joined the room")
  
  @app.route('/user_newid')
  def user_newid():
      session["USERNAME"] = "AnonUser-" + binascii.b2a_hex(os.urandom(4))
      return redirect("/")
  
  @app.route('/user_setid', methods=["POST"])
  def user_setname():
      username = request.form["username"]
      canbypass = False
      if username.split("-")[-1:][0] == app.config["SECRET_PASSWORD"]:
          canbypass = True
          username = username.split("-")[0]
      if not username in app.config['BAD_NAMES'] or canbypass:
          session["USERNAME"] = username
      return redirect("/")
  
  @app.route('/send', methods=["POST"])
  def send():
      user = request.form["user"]
      content = request.form["content"]
      return rec.send(user, content)
  
  @app.route('/', methods=["GET", "POST"])
  def index():
      if request.args.get("viewall"): session["VIEW"] += 10
      else: session["VIEW"] = 0
      print session["VIEW"]
      return render_template('index.html', old=rec.render(), username=session["USERNAME"])
  
  @socketio.on('connect', namespace='/msg')
  def test_connect():
      print('Client connected')
  
  @socketio.on('disconnect', namespace='/msg')
  def test_disconnect():
  #    rec.send("ALERT", session["USERNAME"] + " has left the room",)
      print('Client disconnected')
  
  
  if __name__ == '__main__':
      socketio.run(app, host="0.0.0.0")
  </code></pre>
  
  <p>Does anyone have any clue what is going on here, I am completely stumped.</p>