3

NO KIDDING. My code was working yesterday

So I'm writing a script to get streaming data using twython. But today it's giving me 401 errors. Even with the example code

I tried new keys, and a new app, but it still gives me 401.

However, normal REST api interface in Twython (see next code block) works just fine.

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
print twitter.get_home_timeline()

Some Googlefu led me to this SO thread which suggested using ntpd -q, but this doesn't solve my issue!

Community
  • 1
  • 1
KGo
  • 18,536
  • 11
  • 31
  • 47
  • FWIW, I have the same problem. Strangely, connecting to the streaming API works from my dev box (no 401) but doesn't work from my production server. I have no idea why. Clocks on both servers are in the same time. If I had to guess, I'd guess that the clock on one of Twitter's servers has drifted, and my dev and production boxes are connecting to different IPs. – Ville Laurikari Jun 02 '14 at 07:57
  • @VilleLaurikari For me, it works on heroku, but not on my machine. – KGo Jun 02 '14 at 15:28

1 Answers1

1

This affects only some of the servers behind stream.twitter.com. Perhaps their clocks are off.

Some kind of geo-aware load balancing appears to be used and can the domain name resolves to a number of different IP addresses, depending on where you are doing the resolving.

Connecting to 199.59.148.229 or 199.59.148.138 gives the 401 error for me (these I get resolving from AWS Oregon), but 199.16.156.20 works (this I get resolving from my home network).

Therefore, my temporary workaround for this was to add this to /etc/hosts:

199.16.156.20 stream.twitter.com

I expect the original problem to go away in a few hours, but this works for me, for now.

Ville Laurikari
  • 28,380
  • 7
  • 60
  • 55