【发布时间】:2022-12-19 04:14:32
【问题描述】:
Python's urllib.request.urlopen() will raise an exception if the HTTP status code of the request is not OK (e.g., 404).
This is because the default opener uses the HTTPDefaultErrorHandler class:
A class which defines a default handler for HTTP error responses; all responses are turned into
HTTPErrorexceptions.Even if you build your own opener, it (un)helpfully includes the
HTTPDefaultErrorHandlerfor you implicitly.If, however, you don't want Python to raise an exception if you get a non-OK response, it's unclear how to disable this behavior.
【问题讨论】:
-
you may want to switch to a library that has a different idea of how errors should be handled, like
requests, no? -
@njzk2 I would prefer to do it with the standard library, but yes I could switch to Requests.