Comfy-Org / Comfy-Org/ComfyUI

Websocket API stopt working after installing a Custom Node

Open
#9,622 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 6h
Merged PRs (30d)
155

Description

Hello I Like the Programm and Thanks for your work.

I am trying to use your [ComfyUI]/[script_examples]/websockets_api_example.py
just with my changes to use it as an img2img upscaler with a florence2 model later.

But after installing the [ComfyUI-Florence2](https://github.com/kijai/ComfyUI-Florence2) node the skript stopt working an I dont know why.
In the manager I geht this masage after reinstalling the ComfyUI Destop.

Image

Maybe this has samthing to do with this.

with the [rgthree-comfy](https://github.com/rgthree/rgthree-comfy) nodes I have no problems.

With is my skript.
```
import requests
import websocket
import uuid
import json
import io
from PIL import Image
import os

load_image_node = "10"
eingabe_ordner = "temp"
ausgabe_ordner = "temp_output"

server_address = "127.0.0.1:8000"
client_id = str(uuid.uuid4())
debug_level = 1 # 0=aus, 1=Infos, 2=Debug

# Workflow laden
with open("workflow.json", "r", encoding="utf-8") as f:
workflow_template = json.load(f)

def log(msg, level=1):
"""Hilfsfunktion für Debug-Ausgaben"""
if debug_level >= level:
print(msg)

def upscale_image(image_path, output_path):
log(f"🚀 Starte Upscale für {image_path}", 1)

# 1. Bild hochladen
with open(image_path, "rb") as f:
resp = requests.post(f"http://{server_address}/upload/image", files={"image": f})
if resp.status_code != 200:
log(f"❌ Upload fehlgeschlagen: {resp.text}", 1)
return
upload_info = resp.json()
filename = upload_info["name"]
log(f"✅ Upload erfolgreich: {filename}", 2)

# 2. Workflow anpassen
workflow = workflow_template.copy()
if load_image_node not in workflow or "inputs" not in workflow[load_image_node]:
log(f"❌ Workflow hat keinen Node {load_image_node} mit 'inputs'", 1)
return
workflow[load_image_node]["inputs"]["image"] = filename

# 3. Prompt an Server schicken
p = {"prompt": workflow, "client_id": client_id}
r = requests.post(f"http://{server_address}/prompt", json=p)
if r.status_code != 200:
log(f"❌ Prompt senden fehlgeschlagen: {r.text}", 1)
return
prompt_id = r.json()["prompt_id"]
log(f"📨 Prompt gesendet. Prompt-ID: {prompt_id}", 1)

# 4. Auf Fertigmeldung warten
ws = websocket.WebSocket()
ws.connect(f"ws://{server_address}/ws?clientId={client_id}")
log("🔌 WebSocket verbunden – warte auf Fertigmeldung...", 2)
while True:
msg = json.loads(ws.recv())
log(f"📥 WS: {msg}", 2)
if msg["type"] == "executing" and msg["data"]["node"] is None:
if msg["data"]["prompt_id"] == prompt_id:
log("✅ Workflow fertig ausgeführt", 1)
break
ws.close()

# 5. Output-Dateien aus history lesen
history_resp = requests.get(f"http://{server_address}/history/{prompt_id}")
if history_resp .status_code != 200:
log(f"❌ History konnte nicht geladen werden: {history.text}", 1)
return
history = history_resp.json()
outputs = history[prompt_id]["outputs"]
log(f"📂 Outputs im History: {list(outputs.keys())}", 2)

found = False
for node_id, node_output in outputs.items():
if "images" in node_output:
for img in node_output["images"]:
url = f"http://{server_address}/view?filename={img['filename']}&subfolder={img['subfolder']}&type={img['type']}"
log(f"⬇️ Lade Bild von {url}", 2)
img_bytes = requests.get(url).content
image = Image.open(io.BytesIO(img_bytes))
image.save(output_path)
log(f"✅ Gespeichert: {output_path}", 1)
found = True
if not found:
log("❌ Keine Bilder im Output gefunden!", 1)

# for node_id, node_output in outputs.items():
# if "images" in node_output:
# for img in node_output["images"]:
# img_bytes = requests.get(
# f"http://{server_address}/view?filename={img['filename']}&subfolder={img['subfolder']}&type={img['type']}"
# ).content
# image = Image.open(io.BytesIO(img_bytes))
# image.save(output_path)
# print(f"✅ {image_path} → {output_path}")
# return

# -------------------
# Mehrere Bilder abarbeiten
# -------------------

# sicherstellen, dass der Ausgabeordner existiert
os.makedirs(ausgabe_ordner, exist_ok=True)

for datei in os.listdir(eingabe_ordner):
if datei.lower().endswith((".jpg", ".png", ".jpeg", ".bmp", ".webp")):
input_path = os.path.join(eingabe_ordner, datei)
output_path = os.path.join(ausgabe_ordner, f"{datei}")

upscale_image(input_path, output_path)

#bilder = ["temp/frame_00001.jpg", "temp/frame_00002.jpg", "temp/frame_00003.jpg"]

#for i, pfad in enumerate(bilder, start=1):
# upscale_image(pfad, f"temp_output/frame_{i}.png")

```
and my simpel workflow that i use to test

[workflow.json](https://github.com/user-attachments/files/22046434/workflow.json)

Maybe one of you have a tip how I can uploade und get the imeages In an other way
thanks for your help.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.