Skip to content
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

Connection broken: IncompleteRead #650

Closed
truekonrads opened this issue Sep 9, 2015 · 23 comments
Closed

Connection broken: IncompleteRead #650

truekonrads opened this issue Sep 9, 2015 · 23 comments
Labels
Bug This is regarding a bug with the library Duplicate This is a duplicate

Comments

@truekonrads
Copy link

This happened and wasn't handled properly. Expected behaviour - reconnection

Traceback (most recent call last):¡ãç°¡å
  File "./feeder.py", line 78, in <module>
    stream.filter(**filterargs)
  File "build/bdist.linux-x86_64/egg/tweepy/streaming.py", line 430, in filter
  File "build/bdist.linux-x86_64/egg/tweepy/streaming.py", line 346, in _start
  File "build/bdist.linux-x86_64/egg/tweepy/streaming.py", line 286, in _run
requests.packages.urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(0 bytes read, 512 more expected)', IncompleteRead(0 bytes read, 512 more expected))
@pcarpio
Copy link

pcarpio commented Nov 24, 2015

This is happening to me as well, I updated to the last version which is 3.5.0... i think I'm getting this error everytime I lost connection with the server... I'm not 100% sure any help?

@gambolputty
Copy link

Same with me:

ProtocolError: ('Connection broken: IncompleteRead(0 bytes read, 3346 more expected)', IncompleteRead(0 bytes read, 3346 more expected))

See #448 and #498.

Why am I still getting this error?

@Andergraw
Copy link

Same here, even with Tweepy 3.5.0

@suryasekharmondal
Copy link

Same problem here

@Melvinroy
Copy link

Same issue .Could someone help me solve it?

benfei pushed a commit to benfei/tweepy that referenced this issue Oct 16, 2016
This should handle both cases of incomplete read catched by requests, or
catched by tweepy.

This resolves tweepy#237, resolves tweepy#448, resolves tweepy#536, resolves tweepy#650,
resolves tweepy#691, resolves tweepy#798.

Similar to tweepy#498.
@ghost
Copy link

ghost commented Apr 19, 2017

Same problem for me too. Using python3.4 with tweepy 3.5.0 .

I tried to capture exception using:

except IncompleteRead:
:
:
except ProtocolError as pe:
:
except Exception as ex:
:

Exception details:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/response.py", line 298, in _error_catcher
    yield
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/response.py", line 380, in read
    data = self._fp.read(amt)
  File "/usr/lib/python3.4/http/client.py", line 529, in read
    return super(HTTPResponse, self).read(amt)
  File "/usr/lib/python3.4/http/client.py", line 558, in readinto
    return self._readinto_chunked(b)
  File "/usr/lib/python3.4/http/client.py", line 650, in _readinto_chunked
    n = self._safe_readinto(mvb)
  File "/usr/lib/python3.4/http/client.py", line 709, in _safe_readinto
    raise IncompleteRead(bytes(mvb[0:total_bytes]), len(b))
http.client.IncompleteRead: IncompleteRead(0 bytes read, 512 more expected)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 294, in _run
    raise exception
  File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 263, in _run
    self._read_loop(resp)
  File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 313, in _read_loop
    line = buf.read_line().strip()
  File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 179, in read_line
    self._buffer += self._stream.read(self._chunk_size)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/response.py", line 397, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/usr/lib/python3.4/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/response.py", line 316, in _error_catcher
    raise ProtocolError('Connection broken: %r' % e, e)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(0 bytes read, 512 more expected)', IncompleteRead(0 bytes read, 512 more expected))

@israa-ia1205702
Copy link

@aaronts9
Copy link

aaronts9 commented May 4, 2017

how did this work out for you? Looking but can't seem to get it to work myself

@israa-ia1205702
Copy link

israa-ia1205702 commented May 4, 2017 via email

@Sherm4nLC
Copy link

Is there any error handling solution for this?

@raulmpimentel
Copy link

I have the same problem. Has anyone had any progress?

@diegoje
Copy link

diegoje commented Mar 15, 2018

Same problem here - anybody solved it?

@Vinodhkumar-MT16062
Copy link

Is there any way to solve this problem?

@Vinodhkumar-MT16062
Copy link

Vinodhkumar-MT16062 commented Mar 23, 2018

On simple method to handle/suppress the exception is to override the on_exception() function in tweepy streaming listener class.

Class MyListener(StreamListener):
       def on_status(self, status):
                <ur_code>
 
      def on_data(self,data):
               <ur_code>

        def on_exception(self, exception):
               print(exception)
               return

@diegoje
Copy link

diegoje commented Mar 23, 2018

would adding the above under on_data solve it?

I'll try it and let you know if it works...

@Vinodhkumar-MT16062
Copy link

i don't think adding in on_data works.. just overriding on_exception() as i have done for example is simple and works perfectly.

@bbbbbw
Copy link

bbbbbw commented Apr 11, 2018

Overriding on_exception() works but for me it seems that this exception is raised every 10 minutes, which is really annoying. Is it possible to solve it thoroughly?

@fedecaccia
Copy link

It seems like you are trying to process to much each tweet, and this takes to much time, so twitter disconnects you. Just leave the process of the data to another thread.

@genesiscrew
Copy link

for tweepy v 3.5, the quick and dirty fix is to go to this function in your stream.py: file def _run(self):
in the list of exceptions, just add ProtocolError. you will need to import this by adding this your code: from urllib3.exceptions import ProtocolError

you might also want to comment out the snooze function inside the exception, if you dont want any delay in your real time capturing.

@adamfarnsworth
Copy link

https://developer.twitter.com/en/docs/basics/rate-limiting.html

There is a limit at 15 minutes, so you just have to reconnect after it times out.

@Mitesh-C
Copy link

Mitesh-C commented Mar 3, 2019

i don't think adding in on_data works.. just overriding on_exception() as i have done for example is simple and works perfectly.

i tried with your solution but it keeps coming same error again and again.
Is there any other method to solve it.
Any help is appreciated

@Harmon758
Copy link
Member

Duplicate of #237

@Harmon758 Harmon758 marked this as a duplicate of #237 Apr 26, 2019
@Harmon758 Harmon758 added Bug This is regarding a bug with the library Duplicate This is a duplicate labels Apr 26, 2019
@deadvin
Copy link

deadvin commented Aug 9, 2021

One way to go around is to restart the stream in def on_exception(self, exception): .
If you want to solve the problem you need to make your computations in def on_status(self, status): lighter or to move them out of the stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is regarding a bug with the library Duplicate This is a duplicate
Projects
None yet
Development

No branches or pull requests