HTTP/1.1 401 Unauthorized error when trying to connect to the streaming API with tmhOAuth


#1

Hello,

I know it’s been already discussed through other forum topics, but I can’t find any helpful answer so far.
I am using tmhOAuth PHP lib to connect to the streaming API and everything worked fine until yesterday. now I keep getting this error :

Raw response

HTTP/1.1 401 Unauthorized
WWW-Authenticate: OAuth realm="Firehose"
Content-Type: text/html
Cache-Control: must-revalidate,no-cache,no-store
Transfer-Encoding: chunked
Content-Encoding: gzip

I tried to connect with cURL using twitter’s OAuth tool and it worked, so I am confused about this error message.
anyone getting the same problem ?

I can provide any additional info that would be needed

thank you,

Pierre


#2

You’re not alone! :slight_smile:

Using the same library, we’re experiencing errors when adding users to streams, frequently receiving a 404 “cannot locate stream” error after doing so. Typically, the first request goes through fine, and then anywhere between adding the next 200 - 500 users we experience this error.

This was working absolutely fine until these recent changes, and whilst swapping out tmhOAuth with Phirehose is an option, it’s not ideal if it turns out there’s a minor fix we can implement elsewhere.

Thanks,
Tom


#3

Have you checked to see if your server time is out of sync with the Twitter servers?

(The OAuth tool that generates the cURL command uses the Twitter server time to generate the request.)


#4

Arthur you are damn good !!
the server was indeed 4 min ahead of current time. I set the clock 5 min early and it worked.
You made my day - highly appreciated !!

Thank you,

Pierre


#5

My pleasure! Glad you got it resolved.


#6

Could there be a problem with the library that it tries to reference a non-existent stream? We’ve been seeing a lot of that recently.

What do you get when you try to make raw cURL requests?


#7

Thanks for getting in touch :slight_smile: I’ll double-check raw curl when I’m back in front of a proper computer.

The adding issue is weird - there’s no guarantee for when we’ll get the not found error. Each time, we add 100 users to the stream until we’ve added 1,000. Sometimes the error happens after adding 200, other times after 500. If it gets to 600, generally we won’t see the error occurring, and will have all 1,000 added to the stream.

Based on the debugging I’ve added, I’m 99% sure that the stream ID isn’t being corrupted. As with the parent, this problem only became noticeable yesterday. Been running for well over a year successfully otherwise.


#8

You might also want to take a look at [node:25028, hash=“comment-56485”, title=“my comment on this thread”]. We did make some changes recently, but we have determined that most errors are the result of client libraries/apps not conforming to the HTTP 1.1 standard.


#9

Seeing something very similar. My app also broke 5 days ago after working for months, and I’ve zoned in on “cannot locate stream” while adding to site streams as the culprit.


#10

The problem we were experiencing appears to be caused by to trying to do too much in a single script. We were originally adding up to 1,000 users per script instance, and doing both the adding of users via control streams and the streaming from within the same script.

I’ve now moved the adding part into a dedicated script that handles the control stream adds for all streaming script instances, and that magically appears to have got everything working again :slight_smile:


#11

Hey Thomas, makes no difference to me sadly. Unclear why that would work, but glad your app is running :slight_smile: Thanks!


#12

Honestly, I’m not 100% sure either. My best guess is that we were, in effect, not processing any tweets or heartbeats from the site stream whilst we were adding users, and so this was causing Twitter to terminate the connection.

Without further input from the Twitter devs, we’ll be guessing in the dark to a certain extent. So, for now, that’s my best guess :slight_smile:


#13

Pierre:

Check out this post: [node:24239]

Could that be related to your problem?