The root of the problem could have countless causes. A few pointers.
put in a time.sleep(.5) so the client connection is not rapidly called in succession.
use a timeout watchdog so that a non-response throws an error and can be retried. This is better with streaming and a timer that can be reset by every chunk.