title: How to implement websocket inside a class?
body: <p>I'm trying to use websocket.WebSocketApp inside a class so I could later on use the data retrieved from the websocket:</p>
  
  <pre><code>import requests
  from urlparse import (urlparse, parse_qs)
  import json
  import websocket
  
  class NeuroStream:
  
      def __init__(self, sensor, token):
      self._sensor = sensor
      self.token = token
      self.buf = []
      return
  
      def stream(self):
          self.ws = websocket.WebSocketApp(
              "wss://api.foofoo.com/api/v1/features/" + self._sensor
              + "/real-time/?all=true&amp;access_token=" + self.token,
              on_message=self.on_message,
              on_error=self.on_error,
              on_close=self.on_close)
          self.ws.run_forever()
  
      def on_error(self, error):
          print(error)
  
      def on_close(self):
          print "connection lost"
  
      def on_message(self, message):
          message = json.loads(message)
          biomarkers = message[u'features']
          c1 = biomarkers[u'c1']
          self.buf.append(c1)
  </code></pre>
  
  <p>When I define the functions on_error, on_close and on_message outside the class's scope, replace the self with ws and omit the self from their calls, it works. But then I cannot use   </p>
  
  <pre><code>self.buf.append(c1)  
  </code></pre>
  
  <p>Which is key for later uses  </p>
  
  <p>Edit:
  The code I'm running before the error, and also before the case that works:</p>
  
  <pre><code>from NeuroStream import *
  ns = NeuroStream('a_sensor', 'a_token')
  ns.stream()
  </code></pre>
  
  <p>The error I get is: </p>
  
  <blockquote>
    <p>'No handlers could be found for logger "websocket"'</p>
  </blockquote>
  
  <p>I saw a similar thread, but it didn't help:
  <a href="https://stackoverflow.com/questions/26980966/using-a-websocket-client-as-a-class-in-python">Using a websocket client as a class in python</a></p>