Home > other >  I suddenly receive no stream data from Twitter stream (requests.get(...2/tweets/search/stream))
I suddenly receive no stream data from Twitter stream (requests.get(...2/tweets/search/stream))

Time:04-07

I'm working on a screenshot bot for Twitter using Python.

My app collects tweet from a filtered stream and replies with an image of the tweet.

Yesterday, my bot worked well: connected to stream, and made replies.

Today, it still connects to stream but returns nothing.

Here is the code:

def get_stream(set):
    with requests.get(f"https://api.twitter.com/2/tweets/search/stream?tweet.fields=id,author_id&user.fields=id,username&expansions=author_id,referenced_tweets.id", auth=bearer_oauth, stream=True) as response:
        print(response.status_code)
        if response.status_code == 429:
            print(f"returned code 429, waiting for 60 seconds to try again")
            print(response.text)
            time.sleep(60)
            return
        if response.status_code != 200:
            raise Exception(
                f"Cannot get stream (HTTP {response.status_code}): {response.text}"
                        )
        for response_line in response.iter_lines():
            if response_line:
                print(here)
                json_response = json.loads(response_line)
                print(json.dumps(json_response, indent=4))

I've searched everywhere I know for help on this issue. I've reduced the queries in my request.get line, I've chosen to use a with statement, nothing works.

response.text returns nothing at all, even though response.status_code returns 200.

I have also tried 2 different developer accounts for streaming authentication

CodePudding user response:

This is an issue currently under investigation and not related to the specific code here, you would be best following the Twitter Developer Community discussion.

CodePudding user response:

I figured out what the problem was, it is a problem in the Twitter side that caused streaming to fail for some accounts. It has been resolved now and everything works fine.

  • Related