##  Timeouts  ¶

Most requests to external servers should have a timeout attached, in case the
server is not responding in a timely manner. By default, requests do not time
out unless a timeout value is set explicitly. Without a timeout, your code may
hang for minutes or more.

The **connect** timeout is the number of seconds Requests will wait for your
client to establish a connection to a remote machine (corresponding to the [
connect() ](https://linux.die.net/man/2/connect) ) call on the socket. It’s a
good practice to set connect timeouts to slightly larger than a multiple of 3,
which is the default [ TCP packet retransmission window
](https://datatracker.ietf.org/doc/html/rfc2988) .

Once your client has connected to the server and sent the HTTP request, the
**read** timeout is the number of seconds the client will wait for the server
to send a response. (Specifically, it’s the number of seconds that the client
will wait _between_ bytes sent from the server. In 99.9% of cases, this is the
time before the server sends the first byte).

If you specify a single value for the timeout, like this:

    
    
    r = requests.get('https://github.com', timeout=5)
    

The timeout value will be applied to both the ` connect  ` and the ` read  `
timeouts. Specify a tuple if you would like to set the values separately:

    
    
    r = requests.get('https://github.com', timeout=(3.05, 27))
    

If the remote server is very slow, you can tell Requests to wait forever for a
response, by passing None as a timeout value and then retrieving a cup of
coffee.

    
    
    r = requests.get('https://github.com', timeout=None)
    

Note

The connect timeout applies to each connection attempt to an IP address. If
multiple addresses exist for a domain name, the underlying ` urllib3  ` will
try each address sequentially until one successfully connects. This may lead
to an effective total connection timeout _multiple_ times longer than the
specified time, e.g. an unresponsive server having both IPv4 and IPv6
addresses will have its perceived timeout _doubled_ , so take that into
account when setting the connection timeout.

Note

Neither the connect nor read timeouts are [ wall clock
](https://wiki.php.net/rfc/max_execution_wall_time) . This means that if you
start a request, and look at the time, and then look at the time when the
request finishes or times out, the real-world time may be greater than what
you specified.

Requests is an elegant and simple HTTP library for Python, built for human
beings. You are currently looking at the documentation of the development
release.

###  Useful Links

  * [ Quickstart ](../quickstart/)
  * Advanced Usage 
  * [ API Reference ](../../api/)
  * [ Release History ](../../community/updates/#release-history)
  * [ Contributors Guide ](../../dev/contributing/)

  * [ Recommended Packages and Extensions ](../../community/recommended/)

  * [ Requests @ GitHub ](https://github.com/psf/requests)
  * [ Requests @ PyPI ](https://pypi.org/project/requests/)
  * [ Issue Tracker ](https://github.com/psf/requests/issues)

###  [ Table of Contents ](../../)

  * Advanced Usage 
    * Session Objects 
    * Request and Response Objects 
    * Prepared Requests 
    * SSL Cert Verification 
    * Client Side Certificates 
    * CA Certificates 
    * Body Content Workflow 
    * Keep-Alive 
    * Streaming Uploads 
    * Chunk-Encoded Requests 
    * POST Multiple Multipart-Encoded Files 
    * Event Hooks 
    * Custom Authentication 
    * Streaming Requests 
    * Proxies 
      * SOCKS 
    * Compliance 
      * Encodings 
    * HTTP Verbs 
    * Custom Verbs 
    * Link Headers 
    * Transport Adapters 
      * Example: Specific SSL Version 
      * Example: Automatic Retries 
    * Blocking Or Non-Blocking? 
    * Header Ordering 
    * Timeouts 

###  Related Topics

  * [ Documentation overview ](../../)
    * Previous: [ Quickstart ](../quickstart/ "previous chapter")
    * Next: [ Authentication ](../