Houdini 20.5 hwebserver

hwebserver.Request class

A request made to Houdini’s web server.

On this page

Note

This class is accessible using both hwebserver.WebServerRequest and hwebserver.Request, but hwebserver.Request is preferable.

This object is passed to your registered URL handler function as a container for information from the client request.

Upload example

import tempfile
import hwebserver
import hou


@hwebserver.urlHandler("/blur_image")
def blur_image(request):
    if request.method() == "GET":
        return hwebserver.Response('''
            <p>Upload an image</p>
            <form method="POST" enctype="multipart/form-data">
                <input type="file" name="image_file">
                <input type="submit">
            </form>
        ''')

    if request.method() != "POST":
        return hwebserver.notFoundResponse(request)

    image_file = request.files().get("image_file")
    if image_file is None:
        return hwebserver.errorResponse(request, "No image was posted", 422)
    image_file.saveToDisk()

    # Use a COP2 network to load the image, blur it, and write it to a
    # temporary output file.
    cop2net = hou.node("/img").createNode("img")
    file_cop2 = cop2net.createNode("file")
    file_cop2.parm("filename1").set(image_file.temporaryFilePath())

    blur_cop2 = cop2net.createNode("blur")
    blur_cop2.setFirstInput(file_cop2
    blur_cop2.parm("blursize").set(10)

    rop = cop2net.createNode("rop_comp")
    rop.setFirstInput(blur_cop2)
    rop.parmTuple("f").set((1, 1, 1))
    temp_output_file = tempfile.mkstemp(".jpg")[1]
    rop.parm("copoutput").set(temp_output_file)
    rop.render()

    cop2net.destroy()

    return hwebserver.fileResponse(temp_output_file, delete_file=True)


hwebserver.run(8008, True)

Methods

hwebserver

Classes

Starting and Stopping

Handling Web Requests and Returning Responses

WebSocket

  • WebSocket

    Base class for WebSocket support with the embedded server.

  • hwebserver.webSocket

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

API Calls

  • 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.