title: I was stuck on Exception Handling in Python Requests
body: <p>Contributors.</p>
  
  <p>I'm writing a get title of web program using python requests module.
  I wanna do error handling, but i was stuck.</p>
  
  <p>This is my code.</p>
  
  <pre><code>for i in result:
  try: 
      print("URL : {}".format(i[0]))
      req = requests.get(i[0], headers=headers, timeout=15)
      html = req.text
      soup = BeautifulSoup(html, 'html.parser')
      title = soup.title.string
      print(title)
  
  except requests.ConnectionError as e:
      print("Error : Network Connection Error &lt;{}&gt;".format(e))
  
  except requests.Response.raise_for_status() as e:
      print("Error: Invalid Response Error.")
  
  except requests.exceptions.Timeout as e:
      print("Error: Timeout Error.")
  
  except requests.TooManyRedirects as e:
      print("Error: Too many Redirects")
  
  except:
      print("Error: Unknown Error.")
  </code></pre>
  
  <p>This is Python Console's Answers:</p>
  
  <pre><code>URL : url.com
  Nice URL
  URL : http://0x92B9BDB9
  Traceback (most recent call last):
    File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 387, in _make_request
      conn.request(method, url, **httplib_request_kw)
    File "/usr/lib/python3.4/http/client.py", line 1088, in request
      self._send_request(method, url, body, headers)
    File "/usr/lib/python3.4/http/client.py", line 1126, in _send_request
      self.endheaders(body)
    File "/usr/lib/python3.4/http/client.py", line 1084, in endheaders
      self._send_output(message_body)
    File "/usr/lib/python3.4/http/client.py", line 922, in _send_output
      self.send(msg)
    File "/usr/lib/python3.4/http/client.py", line 857, in send
      self.connect()
    File "/usr/lib/python3.4/http/client.py", line 834, in connect
      self.timeout, self.source_address)
    File "/usr/lib/python3.4/socket.py", line 512, in create_connection
      raise err
    File "/usr/lib/python3.4/socket.py", line 503, in create_connection
      sock.connect(sa)
  socket.timeout: timed out
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/usr/lib/python3/dist-packages/requests/adapters.py", line 330, in send
      timeout=timeout
    File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 562, in urlopen
      body=body, headers=headers)
    File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 391, in _make_request
      (self.host, timeout_obj.connect_timeout))
  urllib3.exceptions.ConnectTimeoutError: (&lt;urllib3.connectionpool.HTTPConnectionPool object at 0x7f0e820c69b0&gt;, 'Connection to 0x92B9BDB9 timed out. (connect timeout=15)')
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "gettitle.py", line 49, in &lt;module&gt;
      req = requests.get(i[0], headers=headers, timeout=15)
    File "/usr/lib/python3/dist-packages/requests/api.py", line 55, in get
      return request('get', url, **kwargs)
    File "/usr/lib/python3/dist-packages/requests/api.py", line 44, in request
      return session.request(method=method, url=url, **kwargs)
    File "/usr/lib/python3/dist-packages/requests/sessions.py", line 455, in request
      resp = self.send(prep, **send_kwargs)
    File "/usr/lib/python3/dist-packages/requests/sessions.py", line 558, in send
      r = adapter.send(request, **kwargs)
    File "/usr/lib/python3/dist-packages/requests/adapters.py", line 387, in send
      raise Timeout(e)
  requests.exceptions.Timeout: (&lt;urllib3.connectionpool.HTTPConnectionPool object at 0x7f0e820c69b0&gt;, 'Connection to 0x92B9BDB9 timed out. (connect timeout=15)')
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "gettitle.py", line 58, in &lt;module&gt;
      except requests.Response.raise_for_status() as e:
  TypeError: raise_for_status() missing 1 required positional argument: 'self'
  </code></pre>
  
  <p>How can i fix it?
  Thanks so much for letting me know!</p>