{"action":"opened","issue":{"url":"https://api.github.com/repos/tweepy/tweepy/issues/582","labels_url":"https://api.github.com/repos/tweepy/tweepy/issues/582/labels{/name}","comments_url":"https://api.github.com/repos/tweepy/tweepy/issues/582/comments","events_url":"https://api.github.com/repos/tweepy/tweepy/issues/582/events","html_url":"https://github.com/tweepy/tweepy/issues/582","id":64854607,"number":582,"title":"Periodic http 401 errors from Twitter","user":{"login":"tehspaceg","id":8031619,"avatar_url":"https://avatars.githubusercontent.com/u/8031619?v=3","gravatar_id":"","url":"https://api.github.com/users/tehspaceg","html_url":"https://github.com/tehspaceg","followers_url":"https://api.github.com/users/tehspaceg/followers","following_url":"https://api.github.com/users/tehspaceg/following{/other_user}","gists_url":"https://api.github.com/users/tehspaceg/gists{/gist_id}","starred_url":"https://api.github.com/users/tehspaceg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tehspaceg/subscriptions","organizations_url":"https://api.github.com/users/tehspaceg/orgs","repos_url":"https://api.github.com/users/tehspaceg/repos","events_url":"https://api.github.com/users/tehspaceg/events{/privacy}","received_events_url":"https://api.github.com/users/tehspaceg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-27T21:25:49Z","updated_at":"2015-03-27T21:25:49Z","closed_at":null,"body":"I am receiving HTTP 401 errors while running through a script I created that reads the Twitter stream and retweets things that match the parameters I have set. It occasionally fails during the retweet section with:\r\n> tweepy.error.TweepError: Twitter error response: status code = 401\r\n\r\nI confirmed that the time is valid on the system and within the ~15 minute wiggle room. The code works the majority of the time, so I am not sure why it would throw the 401 status. Maybe a side question, but is there a more verbose error I can print? I know Twitter will return more information on why it threw 401 (such as unauthorized)\r\n\r\nI snipped out some non-interesting parts, but here is the main part of the code:\r\n\r\n```python\r\ndef doRetweet(id_string):\r\n    # authenticate against the Twitter API\r\n    api = tweepy.API(auth)\r\n    # actually do the retweet\r\n    api.retweet(id_string)\r\n    print('I did the retweet')\r\n    print()\r\n    return\r\nclass StdOutListener(tweepy.StreamListener):\r\n    def on_data(self, data):\r\n            \r\n        # Twitter returns data in JSON format - we need to decode it first\r\n        decoded = json.loads(data)\r\n        \r\n        # grab some data we use later\r\n        tweet_id = decoded['id_str']\r\n\r\n        doRetweet(tweet_id)\r\n\r\n        return True\r\n\r\n    def on_error(self, status):\r\n        print('The below status code was returned from Twitter')\r\n        print(status)\r\n        if status_code == 420:\r\n            #returning False in on_data disconnects the stream\r\n            return False\r\n            \r\n    def on_exception(self, exception):\r\n        raise exception\r\n        return False\r\n\t    \r\ntry:\r\n    if __name__ == '__main__':\r\n        l = StdOutListener()\r\n        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)\r\n        auth.set_access_token(access_token, access_token_secret)\r\n\r\n        # Authenticate with the streaming API and filter what we initially receive\r\n        # spaces are AND operators, while a comma indicates OR. More info here: https://dev.twitter.com/streaming/overview/request-parameters\r\n        stream = tweepy.Stream(auth, l)\r\n        stream.filter(track=['#blah'], languages=['en'])\r\nexcept KeyboardInterrupt:\r\n    sys.exit()\r\n```"}}