Inconsistent responses to user calls - 401 not 404 for some (deleted?) account screen_names



I’m seeing inconsistent error codes returned when querying non-existent screen_names.

For some screen_names, calls to
statuses/user_timeline, _
users/lookup and

all return an (expected) 404. (NOT FOUND)

For others , calls to
users/lookup and
both return the expected 404, but calls to
statuses/user_timeline returns 401 (UNAUTHORISED)

Trapping errors in order to trigger useful and accurate actions in response requires consistency, so this is problematic.

FWIW it does seem that the screen_names that trigger a 401 are accounts that have been registered but subsequently been deleted, while a screen_name for an account that has never been registered consistently triggers a 404.

Python 2.7//Twython//Linux.

It actually seems even more complicated than this.
Sometimes on two consecutive calls with the same API call I can get two different responses: 401/Unauthorised and 401/Error processing your request.

Plus it’s not just non-existent accounts that offer up problems. Suspended accounts give 401, 403 or 404 depending which call is used.
Locked/blocked/blocking accounts seem to give either 401 or 200.

What I don’t know is whether Twython’s error handling is being misleading, or whether Twitter’s error codes are inconsistent, or perhaps it’s 6 of one and 1/2 dozen of the other?


Anyway, I made a little matrix for myself on these errors and managed to work out a means of trapping everything I needed to trap. I still don’t know if this is a Twython or a Twitter issue :slight_smile:
Here’s the matrix fwiw:

                        Non-existent        Non-existent    Suspended
                    (Never registered?)     (deleted?)

get_user_timeline()           404                 401             401

show_user()                   404                 404             403

                        Protected             Blocking      Zero Tweets

get_user_timeline()           401                 401             200***

show_user()                   200                 200             200

                                                            *** Twitter/Twython
                                                                returns empty
                                                                list to this call
                                                                if 0 tweets.    


I’ve actually just encountered this error myself a moment ago. I attempted to call statuses/get_user_timeline on a screen_name that doesn’t exist, and got this:

401:Authentication credentials ( were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system
clock is in sync.
{“request”:"/1.1/statuses/user_timeline.json",“error”:“Not authorized.”}

An odd error for the API to be returning… generally I get 404 errors if I query a non-existent screen_name.

According to my app’s internal database, I last called statuses/get_user_timeline successfully on this particular screen name at 07:23 this morning (less than 12 hours ago) - perhaps this is an issue for screen_names that were deleted recently?

I’m using Twitter4J, and this is the response returned directly from Twitter’s API, so I imagine this issue isn’t specific to Twython.


I’ve just encountered another (perhaps more minor issue) here:

When attempting to query a user who has set their tweets as protected through statuses/get_user_timeline, the API returns this:

401:Authentication credentials ( were missing or incorrect. 
Ensure that you have set valid consumer key/secret, access token/secret, and the system
clock is in sync.
{"request":"\/1.1\/statuses\/user_timeline.json","error":"Not authorized."}

Relevant discussions can be found on the Internet at: or
TwitterException{exceptionCode=[4be80492-0b1a386c], statusCode=401, message=null, code=-1, retryAfter=-1, 
rateLimitStatus=RateLimitStatusJSONImpl{remaining=898, limit=900, resetTimeInSeconds=1518318471, 
secondsUntilReset=345}, version=4.0.6}
        at twitter4j.HttpClientImpl.handleRequest(
        at twitter4j.HttpClientBase.request(
        at twitter4j.HttpClientBase.get(
        at twitter4j.TwitterImpl.get(
        at twitter4j.TwitterImpl.getUserTimeline(
        at antsstyle.artposter.twitter.TwitterRESTAPI.getUserTweets(
        at Source)

The error message ought to be changed to account for this possibility, since it’s relatively easy to check if an account has protected tweets enabled, but it wouldn’t be obvious from reading this error that that was the issue.