[英]tweepy - get remaining Twitter api rate limit while using cursor
Is it possible to get value of HTTP response header from Twitter while using tweepy and Cursors? 使用tweepy和Cursors时是否可以从Twitter获取HTTP响应标头的值?
I want to know the current API remaining rate limit for my app which should be returned in the header as stated in Twitter API docs ( x-rate-limit-remaining: the number of requests left for the 15 minute window ) 我想知道我的应用程序当前的API剩余速率限制,应按Twitter API 文档中所述在标头中返回该限制 ( x-rate-limit-remaining:15分钟窗口内剩余的请求数 )
Example code below: 下面的示例代码:
import tweepy as tw
for status in tw.Cursor(api.user_timeline, screen_name='@somethingsomething', tweet_mode="extended").items():
#do something
Any idea how to achieve this? 任何想法如何实现这一目标?
Is doing non-Tweepy request and read the headers the only way? 是执行非Tweepy请求并读取标头的唯一方法吗?
Found solution on my own, so basically if you enable debug in Tweepy: 我自己找到了解决方案,因此基本上,如果您在Tweepy中启用调试:
import tweepy as tw
tw.debug(True)
you'll get it in the logs, for ex. 您会在日志中得到它,例如。
header: x-rate-limit-remaining: 138 标头:x-rate-limit-remaining:138
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.