zombieyang / sd-ppp

Communicate between Photoshop and SD/SDForge/ComfyUI
MIT License
270 stars 9 forks source link

Sending from Auto1111 to Photoshop, "RuntimeError: File at path [path] does not exist." #28

Closed Jonseed closed 3 months ago

Jonseed commented 3 months ago

I can send images from Photoshop to Auto1111, but when I try to send from Auto1111 to Photoshop, there is an error in the console that says it can't find the file to send. But the file does exist at that path location, so I'm not sure why it can't find the file. For example:

*** API error: GET: http://127.0.0.1:7860/sdppp_download?name=sdppp_0 {'error': 'RuntimeError', 'detail': '', 'body': '', 'errors': 'File at path D:/User-files/Pictures/Stable%20Diffusion%20work/art/OUTPUT/00001-1856313608-a%20photo%20of%20a%20man.png does not exist.'}
    Traceback (most recent call last):
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\anyio\streams\memory.py", line 98, in receive
        return self.receive_nowait()
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\anyio\streams\memory.py", line 93, in receive_nowait
        raise WouldBlock
    anyio.WouldBlock

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\base.py", line 78, in call_next
        message = await recv_stream.receive()
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\anyio\streams\memory.py", line 118, in receive
        raise EndOfStream
    anyio.EndOfStream

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "D:\repos\stable-diffusion-webui\modules\api\api.py", line 186, in exception_handling
        return await call_next(request)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\base.py", line 84, in call_next
        raise app_exc
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\base.py", line 70, in coro
        await self.app(scope, receive_or_disconnect, send_no_error)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\base.py", line 108, in __call__
        response = await self.dispatch_func(request, call_next)
      File "D:\repos\stable-diffusion-webui\modules\api\api.py", line 150, in log_and_time
        res: Response = await call_next(req)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\base.py", line 84, in call_next
        raise app_exc
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\base.py", line 70, in coro
        await self.app(scope, receive_or_disconnect, send_no_error)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\cors.py", line 84, in __call__
        await self.app(scope, receive, send)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\gzip.py", line 26, in __call__
        await self.app(scope, receive, send)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
        raise exc
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
        await self.app(scope, receive, sender)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
        raise e
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
        await self.app(scope, receive, send)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\routing.py", line 718, in __call__
        await route.handle(scope, receive, send)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\routing.py", line 276, in handle
        await self.app(scope, receive, send)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\routing.py", line 69, in app
        await response(scope, receive, send)
      File "d:\repos\stable-diffusion-webui\venv\lib\site-packages\starlette\responses.py", line 338, in __call__
        raise RuntimeError(f"File at path {self.path} does not exist.")
    RuntimeError: File at path D:/User-files/Pictures/Stable%20Diffusion%20work/art/OUTPUT/00001-1856313608-a%20photo%20of%20a%20man.png does not exist.
zombieyang commented 3 months ago

If the path string is correct, it might not a problem of sdppp. I just pass the path to fastapi... https://github.com/zombieyang/sd-ppp/blob/main/sdppp_python/apis.py#L58 Maybe you could try reinstall the python requirements or the whole A1111 WebUI?

Jonseed commented 3 months ago

I did some debugging, and it seems FileResponse is receiving an encoded path (with %20 for spaces, etc), and it should be a decoded path. I think that might be causing the problem. I imported urllib.parse and changed the return value to urllib.parse.unquote(res) and it now works.

Jonseed commented 3 months ago

I looked at the commit 89e8251, and I don't think that will work. The return value of urllib is going nowhere. You can either pass the result of urllib to a new variable, and then send that new variable to FileResponse, or put the entire call to urllib in the value to send to FileResponse, like this: return FileResponse(urllib.parse.unquote(res), media_type='image/png')

zombieyang commented 3 months ago

Great, thank you