Hi, I'm trying to use tweepy's streaming api to listen for tweets but it 
seems when I initialize it, pserve just will not serve on 0.0.0.0:6543

Any idea what might be happening? I will paste trace and code below, note 
the missing 'serving on http://0.0.0.0:6543' message:

Michael

/Users/Shared/webapp/iwb_env/iwb (favorite_tweets ✘)✹✭ ᐅ ../bin/pserve 
development.ini
2015-08-01 14:03:47,729 INFO  [iwb.tweeter.tag_listener][MainThread] 
listening for tags
2015-08-01 14:03:47,797 INFO 
 [requests.packages.urllib3.connectionpool][MainThread] Starting new HTTPS 
connection (1): userstream.twitter.com
/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90:
 
InsecurePlatformWarning: A true SSLContext object is not available. This 
prevents urllib3 from configuring SSL appropriately and may cause certain 
SSL connections to fail. For more information, see 
https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
^CTraceback (most recent call last):
  File "../bin/pserve", line 9, in <module>
    load_entry_point('pyramid==1.5.7', 'console_scripts', 'pserve')()
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/pyramid/scripts/pserve.py",
 
line 58, in main
    return command.run()
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/pyramid/scripts/pserve.py",
 
line 328, in run
    global_conf=vars)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/pyramid/scripts/pserve.py",
 
line 363, in loadapp
    return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 247, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 271, in loadobj
    global_conf=global_conf)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 296, in loadcontext
    global_conf=global_conf)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 320, in _loadconfig
    return loader.get_context(object_type, name, global_conf)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 454, in get_context
    section)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 476, in _context_from_use
    object_type, name=use, global_conf=global_conf)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 406, in get_context
    global_conf=global_conf)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 296, in loadcontext
    global_conf=global_conf)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 328, in _loadegg
    return loader.get_context(object_type, name, global_conf)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 620, in get_context
    object_type, name=name)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
 
line 646, in find_egg_entry_point
    possible.append((entry.load(), protocol, entry.name))
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/pkg_resources.py", 
line 2147, in load
    ['__name__'])
  File "/Users/Shared/webapp/iwb_env/iwb/iwb/__init__.py", line 35, in 
<module>
    from iwb.tweeter.tag_listener import TagListener
  File "/Users/Shared/webapp/iwb_env/iwb/iwb/tweeter/tag_listener.py", line 
83, in <module>
    twitterStream.userstream("with=following")
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/tweepy/streaming.py", 
line 379, in userstream
    self._start(async)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/tweepy/streaming.py", 
line 346, in _start
    self._run()
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/tweepy/streaming.py", 
line 255, in _run
    self._read_loop(resp)
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/tweepy/streaming.py", 
line 298, in _read_loop
    line = buf.read_line().strip()
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/tweepy/streaming.py", 
line 171, in read_line
    self._buffer += self._stream.read(self._chunk_size).decode("ascii")
  File 
"/Users/Shared/webapp/iwb_env/lib/python2.7/site-packages/requests/packages/urllib3/response.py",
 
line 243, in read
    data = self._fp.read(amt)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
 
line 543, in read
    return self._read_chunked(amt)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
 
line 585, in _read_chunked
    line = self.fp.readline(_MAXLINE + 1)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py",
 
line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
 
line 241, in recv
    return self.read(buflen)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
 
line 160, in read
    return self._sslobj.read(len)
KeyboardInterrupt

CODE:
=====

__init__.py just imports the TagListener:

SNIP...


from iwb.tweeter.tag_listener import TagListener

def main(global_config, **settings):
    settings["app_root"] = abspath(dirname(dirname(__file__)))
    initialize_sql(settings)
    
    authn_policy = AuthTktAuthenticationPolicy(
        settings.get("auth.secret"),

..SNIP

CODE:
=====

the TagListener class:

import os
import sys
import time
import json
import tweepy
from tweepy import Stream 
from tweepy.streaming import StreamListener

import logging
LOG = logging.getLogger(__name__)


consumer_key = 'foo'
consumer_secret = 'foo'
access_token = 'foo-foo'
access_token_secret = 'foo'

# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

# Creation of the actual interface, using authentication
api = tweepy.API(auth)

class TagListener(StreamListener):

    def on_data(self, data):
        body=json.loads(data)
        if 'text' in body:
            LOG.info('tag listening in text: ' + body['text'])
            if TagListener._tag_in_text(body['text']):
                api.create_favorite(body['id'])
                LOG.info('create favorite for text: ' + body['text'])
        return True
    def on_error(self, status):
        print(status)

    @classmethod
    def _tag_in_text(cls, text):
        LOG.info('_tag_in_text: {0}'.format(str(text)))

 #       tags = [x.tag for x in all_tags]
#         tags = [x.tag for x in HashTagMgr.get_all_tags()]
        title_list = text.split()
        
        tag_present = False
#         for token in title_list:
#             if token.lower() in tags:
#                 tag_present = True

        return tag_present

LOG.info('listening for tags')
twitterStream = Stream(auth, TagListener()) 
twitterStream.userstream("with=following")


-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to