Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用docker运行时偶尔不会自动下载chromium导致无法生成图片 #14

Closed
kexue-z opened this issue Jul 3, 2021 · 5 comments

Comments

@kexue-z
Copy link
Contributor

kexue-z commented Jul 3, 2021

运行环境:docker

这是docker-compose.yaml

services:
  nonebot:
    build: /data/my_bot/nonebot/
    image: xana278/nonebot:amd64
    container_name: nb
    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime"
      - "/data/my_bot/nonebot:/nonebot"
    environment: 
      - TIME_ZONE=Asia/Shanghai
    command: sh -c "python bot.py"
    working_dir: /nonebot
    restart: always

这是dockerfile

FROM python

ENV TZ=Asia/Shanghai

RUN python3 -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple

RUN pip install nb-cli

RUN nb plugin install nonebot_hk_reporter

这是某次运行时的报错1

07-03 22:53:01 [INFO] nonebot_hk_reporter | send to User(user=436802812, user_type='group'): type: bilibili
from: 科学酱是辣鸡
text: 有人吗,我是谁?我要干什么?
url: 有人吗,我是谁?我要干什么?
pic: https://i0.hdslb.com/bfs/album/39e8cd20234fed94f6656fb81268878085ebb175.jpg
Execution of job "fetch_and_send (trigger: interval[0:00:10], next run at: 2021-07-03 22:53:11 CST)" skipped: maximum number of running instances reached (1)
Execution of job "fetch_and_send (trigger: interval[0:00:30], next run at: 2021-07-03 22:53:31 CST)" skipped: maximum number of running instances reached (1)
Job "fetch_and_send (trigger: interval[0:00:10], next run at: 2021-07-03 22:53:41 CST)" raised an exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
    retval = await job.func(*job.args, **job.kwargs)
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/scheduler.py", line 41, in fetch_and_send
    send_msgs(bot, user.user, user.user_type, await send_post.generate_messages())
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/post.py", line 107, in generate_messages
    msgs.append(await parse_text(text))
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 105, in parse_text
    return await render.text_to_pic_cqcode(text)
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 92, in text_to_pic_cqcode
    data = await self.text_to_pic(text)
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 87, in text_to_pic
    data = await self.render('file://{}'.format(tmp_path), target='div')
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 38, in render
    return await asyncio.wait_for(self.do_render(url, viewport, target, operation), 20)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 481, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 57, in do_render
    self.browser = await launch(args=['--no-sandbox'])
  File "/usr/local/lib/python3.9/site-packages/pyppeteer/launcher.py", line 306, in launch
    return await Launcher(options, **kwargs).launch()
  File "/usr/local/lib/python3.9/site-packages/pyppeteer/launcher.py", line 167, in launch
    self.browserWSEndpoint = get_ws_endpoint(self.url)
  File "/usr/local/lib/python3.9/site-packages/pyppeteer/launcher.py", line 226, in get_ws_endpoint
    raise BrowserError('Browser closed unexpectedly:\n')
pyppeteer.errors.BrowserError: Browser closed unexpectedly:

这是某次运行的报错2

07-03 22:58:04 [INFO] nonebot_hk_reporter | fetch new post from bilibili 4310918: 543252679356877226
07-03 22:58:04 [INFO] nonebot_hk_reporter | send to User(user=436802812, user_type='group'): type: bilibili
from: 科学酱是辣鸡
text: 有人吗,我是谁?我要干什么?[藏狐]
url: 有人吗,我是谁?我要干什么?[藏狐]
pic: https://i0.hdslb.com/bfs/album/e11b17c3c06f819588c09b47632e0ecc9ec273ae.jpg
Job "fetch_and_send (trigger: interval[0:00:10], next run at: 2021-07-03 22:58:13 CST)" raised an exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
    retval = await job.func(*job.args, **job.kwargs)
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/scheduler.py", line 41, in fetch_and_send
    send_msgs(bot, user.user, user.user_type, await send_post.generate_messages())
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/post.py", line 107, in generate_messages
    msgs.append(await parse_text(text))
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 105, in parse_text
    return await render.text_to_pic_cqcode(text)
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 92, in text_to_pic_cqcode
    data = await self.text_to_pic(text)
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 87, in text_to_pic
    data = await self.render('file://{}'.format(tmp_path), target='div')
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 38, in render
    return await asyncio.wait_for(self.do_render(url, viewport, target, operation), 20)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 481, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 55, in do_render
    self.browser = await launch(executablePath='/usr/bin/chromium', args=['--no-sandbox'])
  File "/usr/local/lib/python3.9/site-packages/pyppeteer/launcher.py", line 306, in launch
    return await Launcher(options, **kwargs).launch()
  File "/usr/local/lib/python3.9/site-packages/pyppeteer/launcher.py", line 147, in launch
    self.proc = subprocess.Popen(  # type: ignore
  File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/chromium'

临时解决办法

这样操作之后还能不能用

docker exec -it nb python
Python 3.9.5 (default, Jun 23 2021, 15:01:51) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyppeteer.chromium_downloader import check_chromium, download_chromium
>>> check_chromium()
False
>>> download_chromium()
[W:pyppeteer.chromium_downloader] start chromium download.
Download may take a few minutes.
100%|█████████████████████████████| 108773488/108773488 [00:01<00:00, 66771487.58it/s]
[W:pyppeteer.chromium_downloader] 
chromium download done.
[W:pyppeteer.chromium_downloader] chromium extracted to: /root/.local/share/pyppeteer/local-chromium/588429
>>> check_chromium()
True
@kexue-z
Copy link
Contributor Author

kexue-z commented Jul 3, 2021

补充一下

这是发送查询订阅之后的报错

07-03 23:28:00 [INFO] nonebot | CQHTTP 1505856729 | [message.group.normal]: Message -235313887 from 278220060@[群:363342330] "查询订阅"
07-03 23:28:00 [INFO] nonebot | Event will be handled by <Matcher from bilibili, type=message, priority=1, temp=False>
07-03 23:28:00 [INFO] nonebot | Matcher <Matcher from bilibili, type=message, priority=1, temp=False> running complete
07-03 23:28:00 [INFO] nonebot | Event will be handled by <Matcher from nonebot_hk_reporter, type=message, priority=5, temp=False>
07-03 23:28:00 [INFO] nonebot | Matcher <Matcher from nonebot_hk_reporter, type=message, priority=5, temp=False> running complete
07-03 23:28:00 [ERROR] nonebot | Running matcher <Matcher from nonebot_hk_reporter, type=message, priority=5, temp=False> failed.
Traceback (most recent call last):
  File "/nonebot/bot.py", line 27, in <module>
    nonebot.run(app="bot:app")
  File "/usr/local/lib/python3.9/site-packages/nonebot/__init__.py", line 227, in run
    get_driver().run(host, port, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/nonebot/drivers/fastapi.py", line 170, in run
    uvicorn.run(app or self.server_app,
  File "/usr/local/lib/python3.9/site-packages/uvicorn/main.py", line 386, in run
    server.run()
  File "/usr/local/lib/python3.9/site-packages/uvicorn/server.py", line 49, in run
    loop.run_until_complete(self.serve(sockets=sockets))
  File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 126, in _check_matcher
    await _run_matcher(Matcher, bot, event, state)
> File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 154, in _run_matcher
    await matcher.run(bot, event, state)
  File "/usr/local/lib/python3.9/site-packages/nonebot/matcher.py", line 544, in run
    await handler(self, bot, event, state_)
  File "/usr/local/lib/python3.9/site-packages/nonebot/handler.py", line 81, in __call__
    await self.func(
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/config_manager.py", line 122, in _
    await query_sub.finish(Message(await parse_text(res)))
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 105, in parse_text
    return await render.text_to_pic_cqcode(text)
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 92, in text_to_pic_cqcode
    data = await self.text_to_pic(text)
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 87, in text_to_pic
    data = await self.render('file://{}'.format(tmp_path), target='div')
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 38, in render
    return await asyncio.wait_for(self.do_render(url, viewport, target, operation), 20)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 481, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.9/site-packages/nonebot_hk_reporter/utils.py", line 55, in do_render
    self.browser = await launch(executablePath='/usr/bin/chromium', args=['--no-sandbox'])
  File "/usr/local/lib/python3.9/site-packages/pyppeteer/launcher.py", line 306, in launch
    return await Launcher(options, **kwargs).launch()
  File "/usr/local/lib/python3.9/site-packages/pyppeteer/launcher.py", line 147, in launch
    self.proc = subprocess.Popen(  # type: ignore
  File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/chromium'
^C

{23:28}/data ➭ docker exec -it nb bash     
root@centos:/nonebot# python
Python 3.9.5 (default, Jun 23 2021, 15:01:51) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyppeteer.chromium_downloader import check_chromium, download_chromium
>>> check_chromium()
True
>>> download_chromium()
[W:pyppeteer.chromium_downloader] start chromium download.
Download may take a few minutes.
100%|██████████████████████████████| 108773488/108773488 [00:01<00:00, 73387201.20it/s]
[W:pyppeteer.chromium_downloader] 
chromium download done.
[W:pyppeteer.chromium_downloader] chromium extracted to: /root/.local/share/pyppeteer/local-chromium/588429

环境变量

HK_REPORTER_USE_PIC=TRUE
HK_REPORTER_USE_LOCAL=TRUE

@felinae98
Copy link
Collaborator

HK_REPORTER_USE_LOCAL代表的是使用本地/usr/bin/chromium进行执行,可以取消掉这个环境变量或者在docker build中安装chromium,请参考repo中的Dockerfile

@kexue-z
Copy link
Contributor Author

kexue-z commented Jul 4, 2021

改为HK_REPORTER_USE_LOCAL=FALSE 之后,中文字体显示均为方框
CleanShot 2021-07-04 at 10 15 11

@felinae98
Copy link
Collaborator

docker image中没有安装中文字体,请参考repo中的Dockerfile

@kexue-z
Copy link
Contributor Author

kexue-z commented Jul 4, 2021

想要通过rss订阅 https://rsshub.app/anigamer/new_anime 来获取番剧更新列表,但返回结果内容不含标题。
希望rss订阅功能可以同时获取标题

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

No branches or pull requests

2 participants