Twitter API代码130错误(代码测试请求)

时间:2018-02-05 14:59:56

标签: python rest api twitter tweepy

我已经在python中编写了以下代码,以便粉丝跟踪:

import tweepy
import time
import csv
import sys
import random

consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True, retry_errors=set([401, 404, 500, 502, 503, 504]))

account = 'setavakfi'
log_file = '{}_followers.csv'.format(account)
retry = 0
errorCount = 0

tweepy_cursor = tweepy.Cursor(api.followers, screen_name=account, count=200, cursor=1574812962976647290).pages()
followers_count = []
while True:
    try:
        retry =0
        user = tweepy_cursor.next()
        cursor = tweepy_cursor.next_cursor
        followers_count += user
        print 'Retrieved {} followers accounts'.format(len(followers_count))
        print 'Current cursor: {}'.format(cursor)
        with open(log_file, 'ab') as fd:
            writer = csv.writer(fd)
            for i, user in enumerate(user): 
                writer.writerow([str("@"+user.screen_name), unicode(user.name).encode('utf-8'), str(user.lang), unicode(user.location).encode('utf-8')])
        print "Resting..."
        time.sleep(random.randint(60, 70)  

    except tweepy.TweepError as e:
        print "Error code: {} with message: {}".format(e.api_code, e.message[0]['message'])
        errorCount +=1
        retry += 1
        print 'Retrying in {} seconds'.format(60+retry*5) 
        time.sleep(60+retry*5)
        if retry == 10:
            break

    except StopIteration:
        break   

print 'Done with {} errors'.format(errorCount) 

问题在于,对于给定的光标(1574812962976647290)和帐户(@setavakfi),我只得到错误503(代码130)。这个光标在页面上非常卡住,有8000个空格。整个帐户是> 60,000粉丝。我已经在不同的帐户上尝试了这个代码,有超过60,000个人,并且它可以运行。曾尝试更改ISP,IP地址和Twitter开发帐号。什么都没有改变 你能看出这段代码出了什么问题吗?这个帐户有问题吗?有没有办法自动跳过有问题的光标,看看其他光标是否会出现同样的问题?

提前致谢。 M.

1 个答案:

答案 0 :(得分:0)

我认为该错误是因为使用此帐户的Twitter端服务器超载...我不认为这是您的代码错误。