我正在试验Python模块,以便在3D DCC (Houdini)中运行内部DCC服务器。博士:https://www.sidefx.com/docs/houdini/hwebserver/index.html
在文档中提供了一个示例来设置服务器,以便在发送get请求(https://www.sidefx.com/docs/houdini/hwebserver/Request.html)时执行一些基本的图像处理:
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请求的正确方法是什么?
我目前的代码是:
import requests
resp = requests.get("http://127.0.0.1:8008")我正在浏览器中运行http://127.0.0.1:8008以检查响应。但似乎什么都没发生..。我在这里错过了什么?
谢谢你的建议。
发布于 2022-09-27 15:07:16
我现在已经把这件事做好了,我没有考虑到这条路:
@hwebserver.urlHandler("/blur_image")https://stackoverflow.com/questions/73869556
复制相似问题