title: How to handle urllib's timeout in Python 3?
body: <p>First off, my problem is quite similar to <a href="https://stackoverflow.com/questions/2712524/handling-urllib2s-timeout-python">this one</a>. I would like a timeout of urllib.urlopen() to generate an exception that I can handle.</p>
  
  <p>Doesn't this fall under URLError?</p>
  
  <pre><code>try:
      response = urllib.request.urlopen(url, timeout=10).read().decode('utf-8')
  except (HTTPError, URLError) as error:
      logging.error(
          'Data of %s not retrieved because %s\nURL: %s', name, error, url)
  else:
      logging.info('Access successful.')
  </code></pre>
  
  <p>The error message:</p>
  
  <blockquote>
    <p>resp = urllib.request.urlopen(req, timeout=10).read().decode('utf-8')<br>
        File "/usr/lib/python3.2/urllib/request.py", line 138, in urlopen<br>
        return opener.open(url, data, timeout)<br>
        File "/usr/lib/python3.2/urllib/request.py", line 369, in open<br>
        response = self._open(req, data)<br>
        File "/usr/lib/python3.2/urllib/request.py", line 387, in _open<br>
        '_open', req)<br>
        File "/usr/lib/python3.2/urllib/request.py", line 347, in _call_chain<br>
        result = func(*args)<br>
        File "/usr/lib/python3.2/urllib/request.py", line 1156, in http_open<br>
        return self.do_open(http.client.HTTPConnection, req)<br>
        File "/usr/lib/python3.2/urllib/request.py", line 1141, in do_open<br>
        r = h.getresponse()<br>
        File "/usr/lib/python3.2/http/client.py", line 1046, in getresponse<br>
        response.begin()<br>
        File "/usr/lib/python3.2/http/client.py", line 346, in begin<br>
        version, status, reason = self._read_status()<br>
        File "/usr/lib/python3.2/http/client.py", line 308, in _read_status<br>
        line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")<br>
        File "/usr/lib/python3.2/socket.py", line 276, in readinto<br>
        return self._sock.recv_into(b)<br>
        socket.timeout: timed out  </p>
  </blockquote>
  
  <p>There was a major change from in Python 3 when they re-organised the <code>urllib</code> and <code>urllib2</code> modules into <code>urllib</code>. Is it possible that there was a change then that causes this?</p>