I have some basic code that tries to request a page using BeautifulSoup:
from bs4 import *
from urllib.request import urlopen
try:
soup = BeautifulSoup(urlopen('http://badsite.com/404'))
except urllib.exceptions.HTTPError:
pass
This still raises:
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-24-a0aa8eb7a9ee> in <module>
I have substituted urllib.exceptions.HTTPError
for requests.HTTPError
and requests.exceptions.HTTPError
. All of them still fail to catch the error. How do I properly catch an HTTPError?