Skip to main content

Useful groupings of exceptions for working with network requests.

Project description

neterr

Groupings of exceptions for working with network requests.

When making network requests in python there are a number of possible exceptions to due network issues. These are often a temporarily problem that should be prioritized separately from a bug in code. As a result handling them with a bare except is not safe but knowing exactly what exceptions to handle can be difficult.

Installation

pip install neterr

Error Groups

neterr provides the exception groups SocketErrors, StrictHTTPErrors, AmbiguousHTTPErrors and HTTPErrors.

Usage Example

import urllib.request
from neterr import HTTPErrors
try:
    urllib.request.urlopen('http://127.0.0.1').read()
except HTTPErrors:
    print('caught!')

SocketErrors

SocketErrors contains exceptions that may be raised while working with the socket module.

StrictHTTPErrors

StrictHTTPErrors contains exceptions that may be raised while working with the http module and some common modules that use it (such as urllib and requests). This grouping only contains exceptions that are clearly not the result of code. They may be caused by an infrastructure or configuration problem and are often temporary.

StrictHTTPErrors is a superset of SocketErrors.

AmbiguousHTTPErrors

AmbiguousHTTPErrors contains exceptions that may be raised while working with the http module and some common modules that use it (such as urllib and requests). This grouping contains exceptions that may or may not be caused by code. The most common reason for this ambiguity is that they are the result of an HTTP response with a 4xx or 5xx status. It is recommended to handle 4xx and 5xx responses separately. 4xx responses are often caused by unvalidated user input or another code issue. 5xx responses are often caused by temporarily unavailability in a dependent service.

HTTPErrors

StrictHTTPErrors contains exceptions that may be raised while working with the http module and some common modules that use it (such as urllib and requests).

HTTPErrors is a superset of StrictHTTPErrors and AmbiguousHTTPErrors.

Combining Errors

Exception groups provided by neterr can be combined with other exceptions using the add operator.

from neterr import HTTPErrors

try:
    raise MyException()
except HTTPErrors + MyException:
    print('caught!')

try:
    raise MyException()
except HTTPErrors + (MyException, MyOtherException):
    print('caught!')

try:
    raise MyException()
except HTTPErrors + [MyException, MyOtherException]:
    print('caught!')

Versioning

This package strictly follows semantic versioning.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for neterr, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size neterr-1.1.1-py3-none-any.whl (6.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size neterr-1.1.1.tar.gz (9.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page