Skip to content

Commit

Permalink
fix renamer fail and remove httpx log
Browse files Browse the repository at this point in the history
  • Loading branch information
shininome committed Oct 26, 2024
1 parent 641f0ce commit f3768ed
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
18 changes: 11 additions & 7 deletions backend/src/module/conf/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setup_logger(level: int = logging.INFO, reset: bool = False):
logging.addLevelName(logging.DEBUG, "DEBUG:")
logging.addLevelName(logging.INFO, "INFO:")
logging.addLevelName(logging.WARNING, "WARNING:")
LOGGING_FORMAT = "[%(asctime)s] %(levelname)-8s %(message)s"
LOGGING_FORMAT = "[%(asctime)s] %(levelname)-8s %(message)s"
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(
level=level,
Expand All @@ -29,14 +29,18 @@ def setup_logger(level: int = logging.INFO, reset: bool = False):
logging.StreamHandler(),
],
)
# 全部无效
for logger_name in ["httpx", "httpcore"]:
loggers_to_silence = [
"httpx",
"httpcore",
"hpack",
"hpack.hpack",
]
for logger_name in loggers_to_silence:
logger = logging.getLogger(logger_name)
logger.setLevel(logging.WARNING)
logger.propagate = False
logger.addHandler(logging.NullHandler())
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("requests").setLevel(logging.WARNING)
# logger.propagate = False
# logger.handlers = [NullHandler()]

# 完全抑制 httpx 的日志输出
# httpx_logger = logging.getLogger("httpx")
# http_coro_logger = logging.getLogger("httpcore")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ async def torrents_info(self, status_filter, category, tag=None, limit=0):
"filter": status_filter,
"category": category,
"tag": tag,
"sort": "completion_on",
"reverse": True,
}
if limit:
data.update({"limit": limit})
Expand Down
2 changes: 1 addition & 1 deletion backend/src/module/manager/renamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ async def rename(self):
async with DownloadClient() as client:
# 获取AB 下载的种子详细信息,主要是获取 save_path
# save_path 以 download 查询的为准
bangumi_torrent_infos: list[dict] = await client.get_torrent_info(limit=50)
bangumi_torrent_infos: list[dict] = await client.get_torrent_info(limit=100)
renamer_info_list: list[tuple[Torrent, Bangumi, list[str]]] = []

for bangumi_torrent_info in bangumi_torrent_infos:
Expand Down
19 changes: 14 additions & 5 deletions backend/src/module/network/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,34 @@ def set_proxy():
logger.error(f"[Network] Unsupported proxy type: {settings.proxy.type}")
return proxy

def test_proxy()-> bool:

def test_proxy() -> bool:
with httpx.Client(proxies=set_proxy()) as client:
try:
client.get("https://www.baidu.com")
return True
except httpx.ProxyError:
logger.error(f"[Network] Cannot connect to proxy, please check your proxy username{settings.proxy.username} and password {settings.proxy.password}")
logger.error(
f"[Network] Cannot connect to proxy, please check your proxy username{settings.proxy.username} and password {settings.proxy.password}"
)
return False
except httpx.ConnectError:
logger.error(f"host is down, please check your proxy host {settings.proxy.host}")
logger.error(
f"host is down, please check your proxy host {settings.proxy.host}"
)
return False
except httpx.ConnectTimeout:
logger.error(f"[Network] Cannot connect to proxy {settings.proxy.host}:{settings.proxy.port}")
logger.error(
f"[Network] Cannot connect to proxy {settings.proxy.host}:{settings.proxy.port}"
)
return False


if __name__ == "__main__":
if test_proxy():
with httpx.Client(proxies=set_proxy()) as client:
client.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
client.headers["User-Agent"] = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
)
httpx.get("https://www.baidu.com")
client.get("https://www.baidu.com")

0 comments on commit f3768ed

Please sign in to comment.