Need to sniff for 404 error codes

Bug #1379249 reported by Stuart Bishop
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
python-swiftclient
New
Wishlist
Unassigned

Bug Description

A common pattern with python-swiftclient is:

try:
    conn.head_object(container, obj)
except ClientException as err:
    if err.http_status != 404:
        raise
    [ ... handle not found ... ]

This is ugly and annoying from a developer's perspective. If a specific exception, inheriting from both swiftclient.exceptions.ClientException and the standard Python LookupError, was returned specifiably for HTTP 404 it would become possible to actually write Pythonic code whilst being fully compatible with existing code like the above:

try:
    conn.head_object(container, obj)
except LookupError:
    [ ... handle not found ... ]

Revision history for this message
Nick Moffitt (nick-moffitt) wrote :

The requests library (which is currently the gold standard for handling HTTP in Python) manages to provide both interfaces (exceptions or member variable inspection) successfully:

http://docs.python-requests.org/en/latest/user/quickstart/#response-status-codes

Changed in python-swiftclient:
importance: Undecided → Wishlist
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.