Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tweepy的特定超时错误解决方法_Tweepy - Fatal编程技术网

Tweepy的特定超时错误解决方法

Tweepy的特定超时错误解决方法,tweepy,Tweepy,我知道当我的应用程序的速率限制用尽时,就会出现这段代码,所以我想知道是否有人可以提供关于每分钟/小时/天的请求频率的任何输入。此外,现在每次启动程序时,我的应用程序都会运行以下代码: for tweet in tweepy.Cursor(api.search, search, count=100, tweet_mode='extended').items(1000): retries = 0 max = 10 curWait = 1 waitInc = 1 While retries <

我知道当我的应用程序的速率限制用尽时,就会出现这段代码,所以我想知道是否有人可以提供关于每分钟/小时/天的请求频率的任何输入。此外,现在每次启动程序时,我的应用程序都会运行以下代码:

for tweet in tweepy.Cursor(api.search, search, count=100, tweet_mode='extended').items(1000):
retries = 0
max = 10
curWait = 1
waitInc = 1

While retries < max:
        retries += 1
        try:
                return twitter api call
        except ratelimiterror:
                sleep (curWait)
                curWait += waitInc
                continue
# If we break out of the loop, must have exceeded max retries
raise ratelimiterror

我在包含特定条件的特定tweet上执行try/except,其中我喜欢/rt/comment,并且except子句捕获已经喜欢/rt/comment的tweet时返回的错误。这算是请求吗?如果是这样的话,我是不是要把它浪费在一个异常错误捕获上?它在喜欢/评论/评论方面是成功的,我给程序一个90秒的超时时间(time.sleep(90)),但我猜这还不够?很抱歉问了这么多问题,我不知道该怎么说,所以这并没有回答您的twitter api特定问题,而是一种更通用的处理速率限制的方法

retries = 0
max = 10
curWait = 1
waitInc = 1

While retries < max:
        retries += 1
        try:
                return twitter api call
        except ratelimiterror:
                sleep (curWait)
                curWait += waitInc
                continue
# If we break out of the loop, must have exceeded max retries
raise ratelimiterror
处理速率限制的一种非常常见的模式是退避重试器。当一个请求由于速率限制错误而失败,而不是单纯地重试,或者仅仅失败时,开始重试是很有用的,但速率会逐渐降低

retries = 0
max = 10
curWait = 1
waitInc = 1

While retries < max:
        retries += 1
        try:
                return twitter api call
        except ratelimiterror:
                sleep (curWait)
                curWait += waitInc
                continue
# If we break out of the loop, must have exceeded max retries
raise ratelimiterror
例如,如果请求失败,程序可以在0.5s后重试一次。如果此操作也失败,则可能会等待1s,然后重试

retries = 0
max = 10
curWait = 1
waitInc = 1

While retries < max:
        retries += 1
        try:
                return twitter api call
        except ratelimiterror:
                sleep (curWait)
                curWait += waitInc
                continue
# If we break out of the loop, must have exceeded max retries
raise ratelimiterror
python中已经存在用于执行此操作的库,例如,或者您可以自己实现一个基本版本。它可能看起来像这样(只是伪代码)

retries = 0
max = 10
curWait = 1
waitInc = 1

While retries < max:
        retries += 1
        try:
                return twitter api call
        except ratelimiterror:
                sleep (curWait)
                curWait += waitInc
                continue
# If we break out of the loop, must have exceeded max retries
raise ratelimiterror
retries=0
最大值=10
curWait=1
waitInc=1
重试次数<最大值时:
重试次数+=1
尝试:
返回twitterapi调用
除错误外:
睡眠(等待)
curWait+=waitInc
持续
#如果我们打破了循环,一定超过了最大重试次数
提高速率限制误差

这将最多重试10次,每次延迟1秒,并将延迟量增加1秒。

当您受到速率限制时,可以考虑添加某种退避重试?您是否有具体的想法?
retries = 0
max = 10
curWait = 1
waitInc = 1

While retries < max:
        retries += 1
        try:
                return twitter api call
        except ratelimiterror:
                sleep (curWait)
                curWait += waitInc
                continue
# If we break out of the loop, must have exceeded max retries
raise ratelimiterror