[CentralOH] Web Server Response

William McVey wam at cisco.com
Mon Aug 11 23:08:57 CEST 2008

On Mon, 2008-08-11 at 14:00 -0400, Mark Erbaugh wrote:
> I'm working on a Python web server that allow users to update a database
> using a browser.  It's possible that the user could submit a database
> update that is disallowed by the database server, i.e. deleting a row
> that is a referenced by a foreign key or inserting a duplicate key.
> Is there an HTTP status code that can be used for the response?  I could
> use 400 (bad request), but is there a better choice?

Note that error code 400 is used to convey that the server was unable to
parse or otherwise understand the request. It's not a generic "failure"
because the request was "bad". Some error codes that seem like they
might be appropriate include:

      * 401 Unauthorized
      * 403 Forbidden
      * 405 Method Not Allowed

That last one should probably only be used if your service is truly a
RESTful interface, in that each resource (e.g. a row in the table) has
it's own URI. Presumably this would be in response to a POST or DELETE
method type, and your reply would indicate that only 'GET' is

These error codes are all defined in section 10 of RFC 2616 defining
HTTP/1.1 (viewable at
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 ).

  -- William

More information about the CentralOH mailing list