Twitter API returned a 401 (Unauthorized), An error occurred processing your request

Mona Jalal picture Mona Jalal · Oct 13, 2013 · Viewed 12.2k times · Source

Here's my code for getting the followers and updating a status:

from twython import Twython,TwythonError
APP_KEY='mykey'
APP_SECRET='mysecret'
OAUTH_TOKEN='mytoken'
OAUTH_TOKEN_SECRET='mytokensecret'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
followers = twitter.get_followers_ids(screen_name = "darcythegreat")

for follower_id in followers:
    print follower_id

try:
    twitter.update_status(status='My first status using Twython')
except TwythonError as e:
    print e

And here's the LINK to my Twitter.

After running it I receive the following error:

python tweet.py 
previous_cursor
previous_cursor_str
next_cursor
ids
next_cursor_str
Twitter API returned a 401 (Unauthorized), An error occurred processing your request.

Can you please let me know which steps I am missing?

Answer

Joe Mayo picture Joe Mayo · Oct 14, 2013

There are several reasons why a 401 can occur, some that aren't related to the code you've written. A common reason is a difference in clock times between your and Twitter's server. There are more and here is a FAQ written by @episod/Twitter that might help: https://dev.twitter.com/discussions/204.