Search code examples
pythontwittertweepy

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?

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)

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?


Solution

  • Found solution on my own, so basically if you enable debug in Tweepy:

    import tweepy as tw
    
    tw.debug(True)
    

    you'll get it in the logs, for ex.

    header: x-rate-limit-remaining: 138