-
Notifications
You must be signed in to change notification settings - Fork 998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python and Javascript stream examples break after 5 minutes #34
Comments
Also experiencing this consistently at 5 minute mark. Noticed after these however, I wouldn't receive a 429, so wrapped a try/except around the iter_lines() and continued with a while loop.
A crude patch until Twitter Devs figure out what's happening on their end? |
Glad someone else can confirm this. In production I reconnect, but it seems an imperfect solution as it likely still means I lose data. Furthermore, nodejs seems to behave awkward here – in v12 the stream ends and I can reconnect, but in v14 and v16 nodejs just silently stops code execution: no error to catch, no loop to continue. |
I encounter similar issue with "filtered_stream.py" which was working for hours without any problem a month ago. |
Does anyone have a workaround for the NodeJS version? I've attached listeners to every possible event and the stream just stops without triggering any of my logs. |
Only workaround I found is to reconnect immediately. This only works properly with node v 12.x since in later versions the stream does not stop immediately, but hangs for a considerable amount of time before it disconnects. Another alternative is to use python as python at least throws an error which you can handle (and reconnect). |
Thanks for the reply, I am working with python but I did not fully understand the structure. I want to ask you if you can help. If we consider the example python code (https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/master/Filtered-Stream/filtered_stream.py) where should I put try/except block? And what is the meaning of reconnection in terms of the code should I call get_stream function in the exception. |
I ended up switching to the |
I can reproduce the problem with needle, fetch, python and also https. Using https in the following function as a replacement for the example code function
Do you mind sharing your code, @jahvi (and the node version you are on since this seems to have some impact on the error?) |
@wiertz Actually I just noticed it does stop as well after ~5mins, the only reason I thought it didn't was because it doesn't exit like with I'll try a few more things but I may end up having to switch to the python version. |
I think I managed to fix it now by adding the reconnection logic to the It's been running for 20+ minutes now and it still stops but it reconnects automatically:
EDIT: Ignore this, it doesn't work anymore somehow... I switched to using python + @Da1ne fix above as it's more consistent. |
I have the same issue with python, any solution? Also i get this error with code 104:
Thanks in advance! |
Hey Everyone, it's a problem that arises with some defective http servers that can't be handled by httplib (dependency of requests). So I came up with the following method to tackle it.
You can use loggers to keep track of all the exceptions that are occuring. I know that this is an ugly fix but hey, it works! |
Guys any workaround for NodeJS ? |
It seems we can use PM2 to keep the server running if it crashes |
@twitterdev is anyone going to look into this? I have seen this problem described across node, ruby and python so I don't think it's a problem with client implementations which are consuming stream api. First reports are dated back to October 2020 |
If this is such a long issue then how people are making bots with it ? @arekgotfryd |
@ShivamJoker I would love to know. Do you happen to know? |
Thanks for all the information here and the workarounds to reconnect. We'll see what we can do to integrate those changes into future versions of the sample code as needed. |
@andypiper I've submitted a pull request for the Python one at #36
|
Hi @Da1ne, |
Thank you @andypiper for taking a look at it. Nevertheless I think it has become pretty clear by now that this is not a client side issue. All solutions I have seen thus far just mean catching the error and reconnecting. Afaics this is a backend issue and it would be awesome if this would get some attention there. To be really honest I never expected a solution here, but was trying to raise attention and see if others have this issue. So feel free to close this if it is more appropriately addressed elsewhere. |
Hi ctilly, Really depends what you're doing with your implementation. For me:
Hope this helps! |
Ah! I didn't think of putting the error trap in the "if name" block. I'm trapping the error and then resetting the connection within the main function and that worked really well today. However, I like this idea of trapping the error outside main() because I can reset the whole script if I need to. Thanks for the tip! |
For anyone still following/escaping this error, it would appear the error was on the server side, and was patched yesterday: |
Okay I tested this on JavaScript and seems to be fixed. |
Describe the bug
Both Python and Javascript example code for streaming break after 5 minutes of retrieving tweets. Javascript just hangs/ends without message, Python throws the following error:
To Reproduce
Download example code, set bearer token, run example code. Each time the code is executed, it will stop receiving tweets after the same amount of time, i.e. ~5 minutes. I could reproduce this on two different machines, os (ubuntu+osx), twitter accounts, and three different internet connections.
Expected behavior
Stream should not stop.
The text was updated successfully, but these errors were encountered: