skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. To give more insight over the problem and your solution, I would like people to note that Twitter Authentication mechanism uses OAuth which requires the DateTime of the query to be provided as part of any request header (oauth_timestamp).

    When Twitter receives the query they will verify that the oauth_timestamp is not too old or not invalid. When they have done that they will verify the oauth_signature.

    Most libraries will use the current machine DateTime and use it to create their request. Therefore when using a Third Party tool to access the Twitter API ensure that the DateTime of the machine is correctly setup.

    Some more advanced libraries will allow you to specify a function that will be invoked to access the DateTime. This is particularly useful if your software is distributed to machines for which you cannot ensure the validity of the DateTime.

    I hope this makes some sense.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search