Twitter Stream Mysterious 401:Unauthorized Status with Oauth and Clock Issue
March 8, 2012 Leave a comment
I’ve been facing the following problem with Twitter Stream while using Python: The REST API was working fine, but the Stream API was returning me 401:Unauthorized.
Both, REST and Stream were working fine when using curl with the command provided by the Oauth tool, but while I was trying to make it work with Python, I was not being successful at all, only receiving the 401-thing. At that point nothing seemed to be strange, the response header was:
Content-Type: text/html WWW-Authenticate: Basic realm="Firehose" Cache-Control: must-revalidate,no-cache,no-store Content-Length: 1505 Connection: close
After 2 months struggling with that problem, I discovered that Twitter API will return 401 if your clock is not synchronized. To solve this you need to execute ntpdate. On Ubuntu you can execute the following command:
sudo ntpdate ntp.ubuntu.com
and I guess that you will be able to connect with the Twitter Stream again. On the end, I discovered that this happened because I’ve moved to a different country, and I changed only my clock, without changing my Zone Time. I discovered this because the hour on my clock changed to the one from my home country when I used ntpdate. If this is your case, and you are using Ubuntu, change your Zone Time with the following comand:
sudo dpkg-reconfigure tzdata
Well, I learned a bunch of things in a row

Recent comments