0

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?

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
snapcrack
  • 1,761
  • 3
  • 20
  • 40

1 Answers1

1

Have you tried urllib.error.HTTPError? This answer might help.

S2673
  • 269
  • 4
  • 15