skip to Main Content

Python 3.5.2, Tweepy 3.5.0, Windows 8.1

I’m following a tutorial made by sentdex that shows how to stream data from Twitter using tweepy. (His tutorial is in Python 2 but it is pretty easy to Python 3-ify it)

However, when I run the script, it doesn’t spit out any data. It hangs until I get a 3-way IncompleteRead exception, or until I do Ctrl+C.

Here is my Listener class code:

class listener(StreamListener):

    def on_date(self,data):
        try:
            print(data)
            save = open('twitDB.csv', 'a')
            save.write(data)
            save.write('n')
            save.close()
            return True
        except BaseException as e:
            print('failed on data,',str(e))
            time.sleep(5)

    def on_error(self,status):
        print(status)

auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken,asecret)
twitterStream = Stream(auth=auth, listener=listener())
twitterStream.filter(track=["car"]) 

As you can see, I have it set up to catch errors and print data out while saving it to a csv, but it doesn’t really do anything, just hangs.

Also, for track, I did try to use something less general but it still hanged.

When KeyboardInterrupt is raised:

Traceback (most recent call last):
  File "C:Program FilesPython35libsite-packagesrequestspackagesurllib3co
ntribpyopenssl.py", line 217, in recv_into
    return self.connection.recv_into(*args, **kwargs)
  File "C:Program FilesPython35libsite-packagesOpenSSLSSL.py", line 1352,
in recv_into
    self._raise_ssl_error(self._ssl, result)
  File "C:Program FilesPython35libsite-packagesOpenSSLSSL.py", line 1167,
in _raise_ssl_error
    raise WantReadError()
OpenSSL.SSL.WantReadError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "twittertest.py", line 33, in <module>
    twitterStream.filter(track=["car"])
  File "C:Program FilesPython35libsite-packagestweepystreaming.py", line 4
45, in filter
    self._start(async)
  File "C:Program FilesPython35libsite-packagestweepystreaming.py", line 3
61, in _start
    self._run()
  File "C:Program FilesPython35libsite-packagestweepystreaming.py", line 2
63, in _run
    self._read_loop(resp)
  File "C:Program FilesPython35libsite-packagestweepystreaming.py", line 3
13, in _read_loop
    line = buf.read_line().strip()
  File "C:Program FilesPython35libsite-packagestweepystreaming.py", line 1
79, in read_line
    self._buffer += self._stream.read(self._chunk_size)
  File "C:Program FilesPython35libsite-packagesrequestspackagesurllib3re
sponse.py", line 310, in read
    data = self._fp.read(amt)
  File "C:Program FilesPython35libhttpclient.py", line 448, in read
    n = self.readinto(b)
  File "C:Program FilesPython35libhttpclient.py", line 478, in readinto
    return self._readinto_chunked(b)
  File "C:Program FilesPython35libhttpclient.py", line 573, in _readinto_ch
unked
    chunk_left = self._get_chunk_left()
  File "C:Program FilesPython35libhttpclient.py", line 541, in _get_chunk_l
eft
    chunk_left = self._read_next_chunk_size()
  File "C:Program FilesPython35libhttpclient.py", line 501, in _read_next_c
hunk_size
    line = self.fp.readline(_MAXLINE + 1)
  File "C:Program FilesPython35libsocket.py", line 575, in readinto
    return self._sock.recv_into(b)
  File "C:Program FilesPython35libsite-packagesrequestspackagesurllib3co
ntribpyopenssl.py", line 230, in recv_into
    [self.socket], [], [], self.socket.gettimeout())
KeyboardInterrupt

It’s my first time going with a social media API, so I apologize if I’m missing something obvious. Help would be appreciated, thanks.

2

Answers


  1. Chosen as BEST ANSWER

    Never mind, when I use on_status with status.text, it works, must be something I'm missing.


  2. def on_date(self,data):
    

    This should have been

    def on_data(self,data):
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search