Does the timeout value for Python requests refer to first byte received or whole message? -
the documentation (http://docs.python-requests.org/en/latest/api/#requests.request) explains timeout
value this:
timeout (float or tuple) -- (optional) how long wait server send data before giving up, float, or (connect timeout, read timeout) tuple.
response = requests.post(url, data=post_fields, timeout=timeout)
does mean wait server send single byte, or wait server send "whole" message? in other words, single timeout
value (not tuple), timeout read()
call?
if specify timeout
float (not tuple), equivalent specify tuple components same value:
import requests try: response = requests.post('http://httpbin.org/post', timeout=0.1) except requests.exceptions.timeout e: print(e)
if setting timeout
extremely small (0.001) connecttimeouterror
:
httpconnectionpool(host='httpbin.org', port=80): max retries exceeded url: /post (caused connecttimeouterror(<requests.packages.urllib3.connection.httpconnection object @ 0x039970d0>, 'connection httpbin.org timed out. (connect timeout=0.001)'))
increasing value (0.1) results in successful connection establishment, read()
times out:
httpconnectionpool(host='httpbin.org', port=80): read timed out. (read timeout=0.1)
Comments
Post a Comment