【问题标题】:Pyppeteer and Docker Error: Browser closed unexpectedly:Pyppeteer 和 Docker 错误:浏览器意外关闭:
【发布时间】:2022-07-27 16:44:44
【问题描述】:

在 Docker 和 Python3.10 容器中收到此错误

示例链接如下:https://finance.yahoo.com/quote/BABA/options?p=BABA&date=1653004800

Browser closed unexpectedly:

这是我的 Dockerfile

FROM python:3.10

RUN apt-get update

# TA-Lib
RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
  tar -xvzf ta-lib-0.4.0-src.tar.gz && \
  cd ta-lib/ && \
  ./configure && \
  make && \
  make install && \
  cd .. && \
  rm -R ta-lib ta-lib-0.4.0-src.tar.gz

COPY requirements.txt /tmp/
COPY data/stocks.csv /tmp/data/stocks.csv

RUN pip install --requirement /tmp/requirements.txt
RUN pip freeze >> /tmp/requirement.txt
RUN pyppeteer-install

CMD ["python", "/tmp/app.py"]
async def async_get_options_chain(ticker, date=None, raw=True, headers={'User-agent': 'Mozilla/5.0'}):

    """Extracts call / put option tables for input ticker and expiration date.  If
       no date is input, the default result will be the earliest expiring
       option chain from the current date.

       @param: ticker
       @param: date"""

    site = options.build_options_url(ticker, date)

    browser = await launch({'headless': True, 'options': {'args': ['--no-sandbox', '--disable-setuid-sandbox']}})
    page = await browser.newPage()

    await page.goto(site)
    content = await page.evaluate('document.body.textContent', force_expr=True)

【问题讨论】:

  • 会不会是股票被退市了?
  • @JeJe 每次都失败:(

标签: python docker pyppeteer


【解决方案1】:

似乎解决了这个问题的不是从包安装它,而是从 Dockerfile 安装。现在我必须解决超时问题:)

Dockerfile

# Pyppeteer
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    --no-install-recommends \
    && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
    && apt-get update && apt-get install -y \
    google-chrome-stable \
    --no-install-recommends

# It won't run from the root user.
RUN groupadd chrome && useradd -g chrome -s /bin/bash -G audio,video chrome \
    && mkdir -p /home/chrome && chown -R chrome:chrome /home/chrome

Python

    browser = await launch(executablePath='/usr/bin/google-chrome-stable', headless=True, args=['--no-sandbox'])

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,解决了我的问题确实是 docker 文件没有正确的要求,而且,当我构建 Docker 时,我需要添加--platform=linux/amd64。我在 MB 16" M1 芯片上运行。

    这为我解决了。
    Docker 文件
    ## To run Pyppeteer and chromium
    RUN apt-get install -y gconf-service \
        libasound2 \
        libatk1.0-0 \
        libatk-bridge2.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  \
        libcairo-gobject2 \
        libxinerama1 \
        libgtk2.0-0 \
        libpangoft2-1.0-0 \
        libthai0 \
        libpixman-1-0 \
        libxcb-render0 \
        libharfbuzz0b \
        libdatrie1 \
        libgraphite2-3 \
        libgbm1
    
    RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
    RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/chrome.list
    
    

    当我构建 Docker 时,我添加 --platform=linux/amd64 喜欢

    docker build -f Dockerfile . -t docker-tag --platform=linux/amd64
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      • 2010-11-17
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 2015-02-18
      相关资源
      最近更新 更多