Hello all,
I was using the filtered stream v2 API by using the example Python code shared from dev team on Github. My rule for collecting tweet is not for a too frequent topic, obtaining a tweet may take more than 5-10 minutes sometimes so I do not have problem with about the limitations. However, the code stops running after some minutes but I can not find a reason for this error/execption because the same code could run for hours a month ago. I am suspecting response of the API for keeping the stream awake changed somehow and urllib3 or requests package can not handle. This is because my query is waiting for tweets more than 5 minutes. You may reproduce the situation a rule with a non-frequent keyword (it should wait for tweets) and example code shared above. I tried the example code without any modification but the error is continuing. I tried several different versions including the latest versions for ‘urllib3’ and ‘requests’ packages but none of them worked. I want to share the error with you and it occured with:
requests==2.24.0 as shared in Github, urllib3=1.25.11 and my Python version is 3.8.6.
The error:
Traceback (most recent call last):
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\response.py”, line 696, in _update_chunk_length
self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b’’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\response.py”, line 436, in _error_catcher
yield
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\response.py”, line 763, in read_chunked
self._update_chunk_length()
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\response.py”, line 700, in _update_chunk_length
raise httplib.IncompleteRead(line)
http.client.IncompleteRead: IncompleteRead(0 bytes read)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\models.py”, line 751, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\response.py”, line 571, in stream
for line in self.read_chunked(amt, decode_content=decode_content):
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\response.py”, line 792, in read_chunked
self._original_response.close()
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\contextlib.py”, line 131, in exit
self.gen.throw(type, value, traceback)
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\response.py”, line 454, in _error_catcher
raise ProtocolError(“Connection broken: %r” % e, e)
urllib3.exceptions.ProtocolError: (‘Connection broken: IncompleteRead(0 bytes read)’, IncompleteRead(0 bytes read))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “exp.py”, line 93, in
main()
File “exp.py”, line 89, in main
get_stream(headers, set, bearer_token)
File “exp.py”, line 77, in get_stream
for response_line in response.iter_lines():
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\models.py”, line 795, in iter_lines
for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):
File “C:\Users\MUSTAFA\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\models.py”, line 754, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: (‘Connection broken: IncompleteRead(0 bytes read)’, IncompleteRead(0 bytes read))