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!

  • 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 2 '14 at 7:57
  • @VilleLaurikari For me, it works on heroku, but not on my machine. – Karan Goel Jun 2 '14 at 15:28
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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.