pythongosssss / ComfyUI-Custom-Scripts

Enhancements & experiments for ComfyUI, mostly focusing on UI features
MIT License
1.84k stars 142 forks source link

better_combos: encoded url and substring not found #332

Open universorum opened 2 months ago

universorum commented 2 months ago

Whan add the Lora Loader node, the console will hint substring not found error.

Browser: Firefox 130.0b9 on Windows

Traceback (most recent call last):
  File ".miniforge3/envs/comfy/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 462, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".miniforge3/envs/comfy/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File ".miniforge3/envs/comfy/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "comfy/server.py", line 61, in cache_control
    response: web.Response = await handler(request)
                             ^^^^^^^^^^^^^^^^^^^^^^
  File "/comfy/server.py", line 73, in cors_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "comfy/custom_nodes/ComfyUI-Custom-Scripts/py/better_combos.py", line 58, in get_examples
    pos = name.index("/")
          ^^^^^^^^^^^^^^^
ValueError: substring not found

The problem is the variable name is encoded uri that mean the / will be encoded to %2F. We should call urllib.parse.unquote before find the index of /.

zebbsb commented 2 months ago

yes,it works. Adding 'name = parse.unquote(name)' after 'name = request.match_info["name"]'

Moxie1776 commented 2 months ago

yes,it works. Adding name = parse.unquote(name) after name = request.match_info["name"]

I opened this up in vscode to search for all instances of name = parse.unquote(name), implemented this fix in multiple places across 3 different files, and it did fix all the issues I'm having. Thanks :) Note: added from urllib import parse

LinuxWhiz commented 2 months ago

Harley as And huh

On Tue, Sep 10, 2024 at 10:33 AM Jeff Bluemel @.***> wrote:

yes,it works. Adding 'name = parse.unquote(name)' after 'name = request.match_info["name"]'

I opened this up in vscode, implemented this fix in multiple places, and it did fix all the issues I'm having. Thanks :)

— Reply to this email directly, view it on GitHub https://github.com/pythongosssss/ComfyUI-Custom-Scripts/issues/332#issuecomment-2341015624, or unsubscribe https://github.com/notifications/unsubscribe-auth/BE7VXHI6OAWQMZME6GHU6ZTZV37MDAVCNFSM6AAAAABNOMJUVOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBRGAYTKNRSGQ . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>

CloudWalker-II commented 1 month ago

For those coming across this issue, this solution worked for me as well, I'll try to explain the solution in a bit more detail for those who aren't as well versed in modifying python code (like me).

Go to this folder _...\ComfyUI_windows_portable\ComfyUI\customnodes\ComfyUI-Custom-Scripts\py There are two files that needs to be modified; "better_combos.py" and "model_info.py" Open these files with your preferred text editor like, notepad.

At the top of each file there will be text like this:

import glob
import os
from nodes import LoraLoader, CheckpointLoaderSimple
import folder_paths
from server import PromptServer
from folder_paths import get_directory_by_type
from aiohttp import web
import shutil

At the end add this text: from urllib.parse import unquote

it should look like this:

from folder_paths import get_directory_by_type
from aiohttp import web
import shutil
from urllib.parse import unquote

Then in each document look for all places where you can find these lines (you can use your text editors search function or just have a look yourself):

    name = request.match_info["name"]
    pos = name.index("/")

In between these lines add: name = unquote(name) It should now look like this:

    name = request.match_info["name"]
    name = unquote(name)
    pos = name.index("/")

There is 4 places this text needs to be added in "better_combos.py", and 2 places in "model_info.py".

Save each file when your done and next time you boot up ComfyUI this issue should hopefully be resolved.

Lalimec commented 1 month ago

Is this caused by a comfy update or sth?

zebbsb commented 1 month ago

Is this caused by a comfy update or sth?

Referring to some other discussion, it is caused by comfy update.

Jatts-Art commented 1 month ago

For those coming across this issue, this solution worked for me as well, I'll try to explain the solution in a bit more detail for those who aren't as well versed in modifying python code (like me).

Go to this folder _...\ComfyUI_windows_portable\ComfyUI\customnodes\ComfyUI-Custom-Scripts\py There are two files that needs to be modified; "better_combos.py" and "model_info.py" Open these files with your preferred text editor like, notepad.

At the top of each file there will be text like this:

import glob
import os
from nodes import LoraLoader, CheckpointLoaderSimple
import folder_paths
from server import PromptServer
from folder_paths import get_directory_by_type
from aiohttp import web
import shutil

At the end add this text: from urllib.parse import unquote

it should look like this:

from folder_paths import get_directory_by_type
from aiohttp import web
import shutil
from urllib.parse import unquote

Then in each document look for all places where you can find these lines (you can use your text editors search function or just have a look yourself):

    name = request.match_info["name"]
    pos = name.index("/")

In between these lines add: name = unquote(name) It should now look like this:

    name = request.match_info["name"]
    name = unquote(name)
    pos = name.index("/")

There is 4 places this text needs to be added in "better_combos.py", and 2 places in "model_info.py".

Save each file when your done and next time you boot up ComfyUI this issue should hopefully be resolved.

Doing this does indeed "fix" the issue... technically...... however this seems to change the model's file format if you do so._ I followed the steps exactly, and it results in model file formats all being changed to ".sha256" for whatever reason?

EDIT: Okay after restarting the program suddenly it works? Bruh... no idea why it was giving me an error about the format being wrong, which I sadly didnt keep track of what it has said, but it led me to believe it was due to the file format changing. But it would seem that it actually just created a new file, not replacing the file, my mistake.

CloudWalker-II commented 1 month ago

Glad it helped, not sure what exactly happened in your case but I know that whenever you use the lora loader or the checkpoint loader to check the info for a file it will generate a .sha256 file with the same name as the lora / checkpoint in the same folder. I'm guessing this is a file that these custom nodes use to store extra information in.

aa-parky commented 1 month ago

Just confirming this worked for me too. Thank you.