Requests freeze

I use requeststo get the url for example:

while True:
    try:
        rv = requests.get(url, timeout=1)
        doSth(rv)
    except socket.timeout as e:
        print e
    except Exception as e:
        print e

After it works for a while, it stops working. No exceptions or any errors, as well as suspended. Then I stop the process by typing Ctrl + C from the console. It shows that the process is waiting for data:

  .............
   httplib_response = conn.getresponse(buffering=True) #httplib.py
   response.begin() #httplib.py
   version, status, reason = self._read_status() #httplib.py
   line = self.fp.readline(_MAXLINE + 1) #httplib.py
   data = self._sock.recv(self._rbufsize) #socket.py
KeyboardInterrupt

Why is this happening? Is there a solution?

+4
source share
1 answer

It looks like the server you are sending to requestis clicking on you, that is, sending bytesless than 1 second between each packet (thus not starting your parameter timeout), but slow is enough to make it seem stuck.

, , timeout, .

, timeout latency, .

+5

Source: https://habr.com/ru/post/1652996/


All Articles