Houdini 20.0 Python scripting hou hou.webServer

hou.webServer.Request class

A request made to Houdini’s web server.

On this page

Note

This class is accessible using both hou.WebServerRequest and hou.webServer.Request, but hou.webServer.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 hou


@hou.webServer.urlHandler("/blur_image")
def blur_image(request):
    if request.method() == "GET":
        return hou.webServer.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 hou.webServer.notFoundResponse(request)

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

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

    blur_cop = cop2net.createNode("blur")
    blur_cop.setFirstInput(file_cop)
    blur_cop.parm("blursize").set(10)

    rop = cop2net.createNode("rop_comp")
    rop.setFirstInput(blur_cop)
    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 hou.webServer.fileResponse(temp_output_file, delete_file=True)


hou.webServer.run(8008, True)

Methods

hou.webServer

Classes

Starting and Stopping

Handling Web Requests and Returning Responses

API Calls

  • hou.webServer.apiFunction()

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

  • hou.webServer.APIError

    Raise this exception in apiFunction handlers to indicate an error.