Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 requests - handling exceptions
I'm reading Web Scraping with Python by Ryan Mitchell and trying to use requests instead of urlib. When dealing with exceptions if the issue is that page doesn't exist this code works well:
import requests
from bs4 import BeautifulSoup
    html = requests.get("")
except requests.exceptions.HTTPError as e:
404 Client Error: Not Found for url:
but what to do when server could not be reached at all? Urlib has URLError function but requests module doesn't accept it.

I may have some more issues in the future with exceptions and this topic will be suitable...
Look at A Python guide to handling HTTP request failures.
Truman likes this post
Thank you, I assume that answer is ConnectionError.

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)