500 Error Using Tweepy



I am encountering the following error when using a Tweepy script:

  File "C:\Users\Christian\Dropbox\Twitter\Scrape Candidate Tweets.py", line 34, in <module>
    for status in limit_handled(tweepy.Cursor(api.user_timeline, id = user).items()):
  File "C:\Users\Christian\Dropbox\Twitter\Scrape Candidate Tweets.py", line 8, in limit_handled
    yield cursor.next()
  File "c:\python34\lib\site-packages\tweepy\cursor.py", line 197, in next
    self.current_page = self.page_iterator.next()
  File "c:\python34\lib\site-packages\tweepy\cursor.py", line 108, in next
    data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kargs)
  File "c:\python34\lib\site-packages\tweepy\binder.py", line 245, in _call
    return method.execute()
  File "c:\python34\lib\site-packages\tweepy\binder.py", line 229, in execute
    raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: Twitter error response: status code = 500

It says in the error codes to report any 500’s, so here I am. An almost identical script was working fine yesterday and no longer works. Thanks in advance for any guidance on this one!

Here is the script I am using:

import tweepy
import re
import time

def limit_handled(cursor):
    while True:
            yield cursor.next()
        except tweepy.RateLimitError:
            print("Rate limited.  Waiting 15 minutes.")
            time.sleep(15 * 60)

tokenf = open("C:\\Users\\Christian\\Dropbox\\Twitter\\Access Tokens.txt", 'r')

# Get access tokens
consumer_key = tokenf.readline()
consumer_secret = re.sub('\n', '', tokenf.readline())
access_token = re.sub('\n', '', tokenf.readline())
access_token_secret = tokenf.readline()


# Authenticate
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

# Get user names
userf = open("C:\\Users\\Christian\\Dropbox\\Twitter\\Candidate Usernames.txt", 'r')
usernames = [re.sub('\n', '', x) for x in userf.readlines()]

# Pull statuses which are not retweets
statuses = {}
for user in usernames:
    statuses[user] = []
    for status in limit_handled(tweepy.Cursor(api.user_timeline, id = user).items()):
        if not hasattr(status, 'retweeted_status'):
            statuses[user].append([status.user, status.created_at, status.text])


The Python code is not really readable without proper indentation, please use either fenced code blocks or the code button in the editor to markup the code correctly!


Big thanks to whoever the good samaritan was who updated my post for me last night!