Houdini 19.0 hwebserver

hwebserver.errorResponse function

Generates a Response object representing an HTTP error.

errorResponse(request, error_message, status, use_heading):hwebserver.Response


The Request object passed to the URL handler or API function.

(The function checks the request to see if the client wants a JSON response. If the client provided an Accept: application/json, */* header, this returns the JSON response {"error": error_message}, and error_message may be any JSON-encodable value.)


Error message to display to the user.

(This can be any JSON-encodable value if you know the response will be JSON rather than HTML.)


If the response is an HTML page (instead of JSON), automatically wrap the error_message in an <h1> element.

import hou
import hwebserver

@hwebserver.urlHandler("/node/info/", is_prefix=True)
def node_info(request):
    path = request.path()
    assert path.startswith("/node/info")
    node_path = path[10:]
    node = hou.node(node_path)
    if node is None:
        return hwebserver.errorResponse(request, "Resource not found", 404)
    # ...
See also






  • WebSocket

    Base class for WebSocket support with the embedded server.

  • hwebserver.webSocket

    Decorator for registering WebSocket classes with Houdini’s web server.


  • hwebserver.apiFunction

    Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.

  • hwebserver.APIError

    Raise this exception in apiFunction handlers to indicate an error.