Skip to content

fix(http): 🐛 Fix RequestUtils.get_client() AttributeError#148

Open
Elity wants to merge 2 commits intoAkimioJR:mainfrom
Elity:main
Open

fix(http): 🐛 Fix RequestUtils.get_client() AttributeError#148
Elity wants to merge 2 commits intoAkimioJR:mainfrom
Elity:main

Conversation

@Elity
Copy link
Contributor

@Elity Elity commented Dec 23, 2025

The get_client() method was returning cls.client which doesn't exist, causing AttributeError: type object 'RequestUtils' has no attribute 'client'

  • 🔧 Change __client from class reference to None with type hint

  • ✨ Implement lazy initialization pattern for HTTPClient instance

  • 🐛 Fix incorrect attribute access (cls.client -> cls.__client)

【INFO】     2025-12-23 12:43:10 | 检测到 Alist2Strm 模块配置,正在添加至后台任务

Traceback (most recent call last):

  File "/app/main.py", line 39, in <module>

    Alist2Strm(**server).run, trigger=CronTrigger.from_crontab(cron)

    ^^^^^^^^^^^^^^^^^^^^

  File "/app/modules/alist2strm/alist2strm.py", line 66, in __init__

    self.client = AlistClient(url, username, password, token)

                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/app/utils/multiton.py", line 14, in __call__

    cls._instances[key] = super().__call__(*args, **kwargs)

                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/app/modules/alist/v3/client.py", line 37, in __init__

    self.__client = RequestUtils.get_client()

                    ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/app/utils/http.py", line 351, in get_client

    return cls.client

           ^^^^^^^^^^

AttributeError: type object 'RequestUtils' has no attribute 'client'

Path objects do not support the context manager protocol. The 'with'
statement was incorrectly used with PosixPath objects, causing TypeError
on startup.

  • 🔧 Remove invalid 'with' statement for CONFIG_DIR and LOG_DIR
  • ✨ Directly use Path.exists() and Path.mkdir() methods
运行报错:
Traceback (most recent call last):
  File "/Users/user/code/AutoFilm/./app/main.py", line 10, in <module>
    from app.core import settings, logger
  File "/Users/user/code/AutoFilm/./app/core/__init__.py", line 1, in <module>
    from app.core.config import settings
  File "/Users/user/code/AutoFilm/./app/core/config.py", line 107, in <module>
    settings = SettingManager()
  File "/Users/user/code/AutoFilm/./app/core/config.py", line 26, in __init__
    self.__mkdir()
    ~~~~~~~~~~~~^^
  File "/Users/user/code/AutoFilm/./app/core/config.py", line 33, in __mkdir
    with self.CONFIG_DIR as dir_path:
         ^^^^^^^^^^^^^^^
TypeError: 'PosixPath' object does not support the context manager protocol

Huiting Chen added 2 commits December 23, 2025 12:49
The get_client() method was returning cls.client which doesn't exist, causing AttributeError: type object 'RequestUtils' has no attribute 'client'

- 🔧 Change __client from class reference to None with type hint

- ✨ Implement lazy initialization pattern for HTTPClient instance

- 🐛 Fix incorrect attribute access (cls.client -> cls.__client)
Path objects do not support the context manager protocol. The 'with' statement was incorrectly used with PosixPath objects, causing TypeError on startup.

- 🔧 Remove invalid 'with' statement for CONFIG_DIR and LOG_DIR

- ✨ Directly use Path.exists() and Path.mkdir() methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant