首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Python请求发送到本地Get服务器(运行在Houdini中)

如何将Python请求发送到本地Get服务器(运行在Houdini中)
EN

Stack Overflow用户
提问于 2022-09-27 14:47:02
回答 1查看 18关注 0票数 0

我正在试验Python模块,以便在3D DCC (Houdini)中运行内部DCC服务器。博士:https://www.sidefx.com/docs/houdini/hwebserver/index.html

在文档中提供了一个示例来设置服务器,以便在发送get请求(https://www.sidefx.com/docs/houdini/hwebserver/Request.html)时执行一些基本的图像处理:

代码语言:javascript
复制
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 COP network to load the image, blur it, and write it to a
    # temporary output file.
    copnet = hou.node("/img").createNode("img")
    file_cop = copnet.createNode("file")
    file_cop.parm("filename1").set(image_file.temporaryFilePath())

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

    rop = copnet.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()

    copnet.destroy()

    return hwebserver.fileResponse(temp_output_file, delete_file=True)


hwebserver.run(8008, True)

我想在在Houdini上运行服务器的同一台机器上进行本地测试。

使用python发送get请求的正确方法是什么?

我目前的代码是:

代码语言:javascript
复制
import requests

resp = requests.get("http://127.0.0.1:8008")

我正在浏览器中运行http://127.0.0.1:8008以检查响应。但似乎什么都没发生..。我在这里错过了什么?

谢谢你的建议。

EN

回答 1

Stack Overflow用户

发布于 2022-09-27 15:07:16

我现在已经把这件事做好了,我没有考虑到这条路:

代码语言:javascript
复制
@hwebserver.urlHandler("/blur_image")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73869556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档