0

Pyppeteer(puppeteer 的 python 端口)正在尝试下载 linux-chrome 但无法下载。

这是一个 python 项目,我已将其 docker 化并使用无服务器部署到 AWS Lambda 中。我正在使用无服务器将 python 依赖项部署到 lambda 层。

我在谷歌上找不到任何明确的东西来告诉我如何使用 python 运行时为 chrome 浏览器自动化设置适当的 lambda。

无服务器

provider:
  name: aws
  runtime: python3.7

functions:
  main:
    handler: main.handler
    package:
      include:
        - src/main.py
    layers:
      - {Ref: PythonRequirementsLambdaLayer}
    environment:
      REGION_NAME: us-west-2

custom:
  pythonRequirements:
    dockerizePip: true
    zip: true
    dockerImage: mydocker:latest
    layer: true

plugins:
  - serverless-python-requirements

傀儡师

        self.browser = await pyppeteer.launch({
            'headless': True,
            'args': [
                '--no-sandbox', 
                '--disabled-setuid-sandbox', 
                '--disable-dev-profile', 
                '--user-data-dir=/tmp'
            ]
        })

dockerfile

FROM python:3.7-slim

RUN apt-get -y update
RUN apt-get -y install curl
RUN apt-get install -y git
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

ENV REGION_NAME='us-west-2'
ENV XDG_CACHE_HOME='/tmp/.cache'
ENV PYPPETEER_HOME='tmp/'

COPY . src/

WORKDIR src

RUN pip3 install -r requirements.txt

RUN python3 -c 'import pyppeteer; pyppeteer.chromium_downloader.download_chromium()'

错误信息

{
    "statusCode": 400,
    "message": "[Errno 30] Read-only file system: '/home/sbx_user1051'",
    "trace": [
        "Traceback (most recent call last):\n",
        "  File \"/var/task/main.py\", line 18, in handler\n    result = loop.run_until_complete(main())\n",
        "  File \"/var/lang/lib/python3.7/asyncio/base_events.py\", line 584, in run_until_complete\n    return future.result()\n",
        "  File \"/var/task/main.py\", line 68, in main\n    ring_results = await pyp_client.get_ring_results()\n",
        "  File \"/var/task/clients/pyppeteer_client.py\", line 40, in get_ring_results\n    await self.ready_the_browser()\n",
        "  File \"/var/task/clients/pyppeteer_client.py\", line 18, in ready_the_browser\n    await self.__create_browser_instance()\n",
        "  File \"/var/task/clients/pyppeteer_client.py\", line 32, in __create_browser_instance\n    '--user-data-dir=/tmp'\n",
        "  File \"/tmp/sls-py-req/pyppeteer/launcher.py\", line 311, in launch\n    return await Launcher(options, **kwargs).launch()\n",
        "  File \"/tmp/sls-py-req/pyppeteer/launcher.py\", line 125, in __init__\n    download_chromium()\n",
        "  File \"/tmp/sls-py-req/pyppeteer/chromium_downloader.py\", line 136, in download_chromium\n    extract_zip(download_zip(get_url()), DOWNLOADS_FOLDER / REVISION)\n",
        "  File \"/tmp/sls-py-req/pyppeteer/chromium_downloader.py\", line 125, in extract_zip\n    zf.extractall(str(path))\n",
        "  File \"/var/lang/lib/python3.7/zipfile.py\", line 1616, in extractall\n    self._extract_member(zipinfo, path, pwd)\n",
        "  File \"/var/lang/lib/python3.7/zipfile.py\", line 1662, in _extract_member\n    os.makedirs(upperdirs)\n",
        "  File \"/var/lang/lib/python3.7/os.py\", line 211, in makedirs\n    makedirs(head, exist_ok=exist_ok)\n",
        "  File \"/var/lang/lib/python3.7/os.py\", line 211, in makedirs\n    makedirs(head, exist_ok=exist_ok)\n",
        "  File \"/var/lang/lib/python3.7/os.py\", line 211, in makedirs\n    makedirs(head, exist_ok=exist_ok)\n",
        "  [Previous line repeated 2 more times]\n",
        "  File \"/var/lang/lib/python3.7/os.py\", line 221, in makedirs\n    mkdir(name, mode)\n",
        "OSError: [Errno 30] Read-only file system: '/home/sbx_user1051'\n"
    ]
}
4

1 回答 1

2

我建议你ENV PYPPETEER_HOME='tmp/'改为

ENV PYPPETEER_HOME='/tmp/'

似乎PYPPETEER尝试mkdir/home/sbx_user1051/tmp其中没有write权限

于 2019-08-26T09:19:03.277 回答