ComfyUI-Custom-Scripts icon indicating copy to clipboard operation
ComfyUI-Custom-Scripts copied to clipboard

better_combos: encoded url and substring not found

Open universorum opened this issue 1 year ago • 9 comments

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 /.

universorum avatar Sep 01 '24 02:09 universorum

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

zebbsb avatar Sep 07 '24 07:09 zebbsb

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

Moxie1776 avatar Sep 10 '24 14:09 Moxie1776

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>

LinuxWhiz avatar Sep 11 '24 00:09 LinuxWhiz

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\custom_nodes\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.

CloudWalker-II avatar Sep 23 '24 23:09 CloudWalker-II

Is this caused by a comfy update or sth?

Lalimec avatar Sep 24 '24 00:09 Lalimec

Is this caused by a comfy update or sth?

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

zebbsb avatar Sep 24 '24 14:09 zebbsb

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\custom_nodes\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.

Jatts-Art avatar Sep 28 '24 04:09 Jatts-Art

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.

CloudWalker-II avatar Sep 28 '24 22:09 CloudWalker-II

Just confirming this worked for me too. Thank you.

aa-parky avatar Oct 12 '24 10:10 aa-parky