Search code examples
twittertwitter-streaming-apitwython

Twitter streaming API not responding on production, but OK on dev server


I have been listening to the Twitter public stream with Twython with no problem but the production server stopped receiving any tweets for a couple of days.

I've created a simple test case:

>>> from twython import TwythonStreamer
>>> 
>>> class TestStreamer(TwythonStreamer):
...     def on_success(self, data):
...         print data
... 
>>> stream = TestStreamer(KEY, SECRET, TOKEN, TOKEN_SECRET)
>>> 
>>> stream.statuses.filter(track='clinton,trump')

This snippet runs on the development server. Tweets instantly start flowing in. On production it again seems to be listening, there are no errors thrown, but no tweets.

I thought it might be the firewall on the server, or the server might be blacklisted on Twitter's side. But when I try the same query with curl command generated by the Twitter signature generator dev tool, with the same token set, the command starts receiving tweets instantly both on the development and production servers without any problem. I think this curl test eliminates these firewall, blacklist or token issues options.

What do you think the problem might be? Any help is greatly appreciated. Thanks.


Solution

  • It turned out to be server clock drift on the AWS EC2 servers that caused the authentication to fail due to the usage of an expired timestamp. It was also Twython suppressing the exception which made the case more obscure.

    I tried with the Twitter client Birdy and get the "Unauthorized" response. Then I came across this post.

    So I made a clock sync and everything is back to normal again:

    sudo ntpdate -s time.nist.gov