Lately I’ve been getting this error fairly commonly
<class ‘TwitterAPI.TwitterError.TwitterConnectionError’>
(“Connection broken: ConnectionResetError(104, ‘Connection reset by peer’)”
And I’m wondering if something in my program is causing it, or if it’s just disconnections between my program and twitter that are to be expected.
Is there something I can do to reduce this error or do I just have to deal with it?
I’m streaming tweets using the v1.1 API and code that looks like this:
r = api.request('statuses/filter', {'follow': user_ids})
I’m currently handling the error by waiting a short time (~a minute) and restarting my loop. Is there a better way?
I think you can try to reconnect faster than that - but with an exponential back off strategy Sampled stream - Handling disconnections | Docs | Twitter Developer Platform (this is for v2 but applies to v1.1 too)
Is this type of error caused by something in my program that I can fix/diminish?, or is it just to be expected and unavoidable?
Also that link has this part:
- Back off linearly for TCP/IP level network errors. These problems are generally temporary and tend to clear quickly. Increase the delay in reconnects by 250ms each attempt, up to 16 seconds.
- Back off exponentially for HTTP errors for which reconnecting would be appropriate. Start with a 5 second wait, doubling each attempt, up to 320 seconds.
- Back off exponentially for HTTP 429 errors Rate limit exceeded. Start with a 1 minute wait and double each attempt. Note that every HTTP 429 received increases the time you must wait until rate limiting will no longer be in effect for your account.
Which seems really useful! But how do I know which type of error I have between a TCP/IP level network error, HTTP error, or an HTTP 429 error?
The actual errors from python or HTTP error codes and twitter error codes should help, so the twitter errors are listed in Twitter API Response Codes & Error Support | Twitter Developer Platform but this means the connection and HTTP request technically succeeded, but if it doesn’t get that far, you’ll get some HTTP level errors, and if you don’t get an HTTP error you’ll get an exception in code for TCP/IP level errors.
1 Like
Okay if I have you correctly:
TCP/IP are errors that happen at the level of python and internet connections. They won’t show up on the list. These types of errors should be dealt with by backing off linearly from 250ms each attempt, up to 16.
HTTP errors are the ones that have twitter error codes on that list (minus 429). They should be dealt with by backing off exponentially from 5 second wait, doubling each attempt, up to 320 seconds
HTTP 429 errors are specifically rate limit errors, where you are making more requests of twitter servers than they allow your account per unit time. They are HTTP errors that give the specific error code 429. They should be dealt with by starting with a 1 minute wait and double each attempt
Also, the error that I have in this thread:
(“Connection broken: ConnectionResetError(104, ‘Connection reset by peer’)”
Is a TCP/IP error, and I know that because it’s not on the twitter list
Do I have that right?
1 Like
system
Closed
#7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.