vale46n1/immich_duplicate_finder

Cannot fetch assets

agross opened this issue · 7 comments

After fixing #1 by moving the save_settings_to_db method to the top of the file, I now get this when trying to fetch assets:

Fetch con cache
2024-03-21 21:49:58.312 Uncaught app exception
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.8/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.8/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.8/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 542, in _run_script
    exec(code, module.__dict__)
  File "/Users/agross/Downloads/immich_duplicate_finder/app.py", line 294, in <module>
    main()
  File "/Users/agross/Downloads/immich_duplicate_finder/app.py", line 274, in main
    assets = fetch_assets()
             ^^^^^^^^^^^^^^
  File "/Users/agross/Downloads/immich_duplicate_finder/app.py", line 121, in fetch_assets
    assets = response.json()
             ^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

did you include the address with the port? "http://192.168.1.100:8090"

No, my Immich runs on a domain like https://immich.example.com.

could you try with the local domain?

Not sure what you mean by "the local domain". An address similar to the above is the only way to reach my Immich instance.

OK, found it: https://immich.example.com works, https://immich.example.com/ does not. The trailing slash causes requests to //api/... which returns plain HTML instead of JSON.

This is the next exception which happened on pair #5:

Fetch con cache
2024-03-21 22:35:33.351 Uncaught app exception
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 542, in _run_script
    exec(code, module.__dict__)
  File "/Users/agross/Downloads/immich_duplicate_finder/app.py", line 293, in <module>
    main()
  File "/Users/agross/Downloads/immich_duplicate_finder/app.py", line 275, in main
    show_duplicate_photos(assets,limit)
  File "/Users/agross/Downloads/immich_duplicate_finder/app.py", line 193, in show_duplicate_photos
    image1 = np.array(stream_asset(original['id'],immich_server_url))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 210, in wrapper
    return cached_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 239, in __call__
    return self._get_or_create_cached_value(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 266, in _get_or_create_cached_value
    return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 322, in _handle_cache_miss
    computed_value = self._info.func(*func_args, **func_kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/agross/Downloads/immich_duplicate_finder/app.py", line 90, in stream_asset
    image = Image.open(image_bytes)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/PIL/Image.py", line 3309, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x10288ccc0>

First of all I revised the code to handle that situation.
base_url = immich_server_url.rstrip('/')
Let's close this and open a new issue....just for tracking