菜比之路

走菜比的路,让大牛说去吧
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

【python】requests 异常处理

Posted on 2019-11-29 11:27  毕加索的ma  阅读(4077)  评论(0编辑  收藏  举报

以下是request.exceptions下的各种异常错误:

RequestException:

HTTPError(RequestException)

UnrewindableBodyError(RequestException)

RetryError(RequestException)

ConnectionError(RequestException) ProxyError(ConnectionError)

SSLError(ConnectionError)

ConnectTimeout(ConnectionError, Timeout)

Timeout(RequestException) ReadTimeout

URLRequired(RequestException)

TooManyRedirects(RequestException)

MissingSchema(RequestException, ValueError)

InvalidSchema(RequestException,ValueError)

InvalidURL(RequestException,ValueError)

InvalidHeader(RequestException,ValueError)

ChunkedEncodingError(RequestException)

StreamConsumedError(RequestException,TypeError)

ContentDecodingError(RequestException,BaseHTTPError)

在实际应用的过程中,我们可以把请求放在try下,把可能发生的异常用except获取