question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AsyncStreamingClient 429 error on reconnect from uncaught exceptions

See original GitHub issue

First, thank you so much for (finally) adding an asynchronous Twitter API v2 streaming client in Tweepy v4.10. It works great and I like the fact that it can disconnect immediately rather than waiting for the next response from Twitter. However, I ran into a strange bug with this new implementation.

I subclassed AsyncStreamingClient to make it run forever until the user pressed <kbd>Ctrl</kbd>+<kbd>C</kbd> instead of exiting on its own when an uncaught exception occurred. Every time the client reconnects after the unhandled exception, I would get a 429 error for about 30 seconds before it would connect to the stream endpoint just fine. But the weird part is when I manually shut down my program and start it back up within those 30 seconds, the client connects successfully on the first try.

Here’s the code I used to reproduce this scenario:

import asyncio
import logging
import sys
from tweepy.asynchronous.streaming import AsyncStreamingClient

BEARER_TOKEN = "yourtokenhere"


class RunForeverClient(AsyncStreamingClient):
    async def on_keep_alive(self):
        await super().on_keep_alive()
        # This will be triggered on the first keepalive signal once connected
        raise Exception("Uncaught exception")

    def run_forever(self) -> asyncio.Task:
        async def task():
            while True:
                await self.filter()  # or self.sample()
                if sys.exc_info()[0] == KeyboardInterrupt:
                    break
        return asyncio.create_task(task())


async def main():
    client = RunForeverClient(BEARER_TOKEN)
    await client.run_forever()


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Harmon758commented, Oct 29, 2022

Thanks for the bug report and the reproducer. This took me a bit to wrangle, but it seems like this was due to lingering open sockets from closed SSL transports.

0reactions
Harmon758commented, Oct 1, 2022

@nono-london That’s unrelated to this issue.

You’re likely encountering a 409 error due to a conflict in your rules. The latest development version of Tweepy now logs the specific error message, which you can probably use to determine the exact issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting HTTP error 429 from StreamingClient when no other ...
The error occurs in the middle of a long streaming(~4hrs). Sometimes the stream client starts to work properly after trying to reconnect itself ......
Read more >
AsyncStreamingClient 429 error on reconnect ... - Python 博客
I subclassed AsyncStreamingClient to make it run forever until the user pressed Ctrl+C instead of exiting on its own when an uncaught exception...
Read more >
tweepy - Bountysource
Every time the client reconnects after the unhandled exception, I would get a 429 error for about 30 seconds before it would connect...
Read more >
What an HTTP Error 429 Means & How to Fix It - HubSpot Blog
HTTP Error 429 is an HTTP response status code that indicates the client application has surpassed its rate limit, or number of requests...
Read more >
AsyncStreamingClient 429 error on reconnect from ... - bytemeta
Every time the client reconnects after the unhandled exception, I would get a 429 error for about 30 seconds before it would connect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found