Tweepy. The function 'on_data' blocks the next part of code

Viewed 18

Can you please tell me why when I use on_data and on_response function at the same time, the latter does not work? I understand that the first function contains all information, but I already wrote a lot of code using on_response function and I just wanted to get a small part of on_data function.

class MyStream(tweepy.StreamingClient):
   def on_data(self, raw_data):
      print(raw_data)
    
   def on_response(self, response):
      print(response) #this part of code is not working
1 Answers

Whenever the StreamingClient gets any data, on_data will be called.
on_data takes in the raw data (the json) and converts it into Tweepy Objects and then calls other functions like on_tweet, on_includes, on_errors, and finally on_response.

And that's the reason why on_response is never called because you're overriding the default on_data function that would call on_response


Line 899 is where on_data is defined for the StreamingClient. https://github.com/tweepy/tweepy/blob/master/tweepy/streaming.py#L899

Related