Google cloud platform 在google云运行应用程序中安装google chrome for python selenium

Google cloud platform 在google云运行应用程序中安装google chrome for python selenium,google-cloud-platform,dockerfile,google-chrome-headless,google-cloud-build,google-cloud-run,Google Cloud Platform,Dockerfile,Google Chrome Headless,Google Cloud Build,Google Cloud Run,我正在尝试在我正在开发的云运行应用程序中使用selenium。该应用程序在我的本地机器上正常工作,但在我将其部署到google cloud run上后就无法工作了。我遇到的错误与谷歌云上没有安装chromedriver.exe有关 这是日志中的回溯错误: Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app resp

我正在尝试在我正在开发的云运行应用程序中使用selenium。该应用程序在我的本地机器上正常工作,但在我将其部署到google cloud run上后就无法工作了。我遇到的错误与谷歌云上没有安装
chromedriver.exe
有关

这是日志中的回溯错误:

Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/app/main.py", line 22, in daily_login login.create_access_token() File "/app/scripts/loginFlow/login.py", line 30, in create_access_token request_token = generate_request_token() File "/app/scripts/loginFlow/login.py", line 61, in generate_request_token driver = webdriver.Chrome() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__ self.service.start() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
该回溯的相关部分似乎是
消息:“chromedriver”可执行文件需要位于路径中
。如何获取此google cloud run应用程序路径中的chromedriver可执行文件


现在,我试着做些什么呢

首先,我找到了这篇文章:并按照评论中留下的说明进行了操作。我查看了这一点,并将我的
Dockerfile
建模为类似于建议的内容。唯一的区别是我使用的是Python3.6而不是Python3.7:

# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.6-slim

# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils

# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install


# Install Python dependencies.
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 main:app
我还将
chromedriver binary==77.0.3865.40.0
添加到我的
requirements.txt
文件中

当我尝试使用
gcloud builds submit
部署它时,出现以下错误:

/bin/sh:1:wget:未找到
命令'/bin/sh-cwgethttps://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb'返回了一个非零代码:127
错误
错误:生成步骤0“gcr.io/cloud builders/docker”失败:步骤退出,状态为非零:127


我一直在试图在线找到解决此错误的方法,但我迷路了。非常感谢您的帮助

添加命令以安装
wget

# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install wget

添加命令以安装
wget

# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install wget

我也面临着同样的问题,终于让它起作用了!这是我的文件:

FROM python:3.7

# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils default-jdk

# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install

# Install Python dependencies.
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

# Copy local code to the container image.
WORKDIR /app
COPY . .
CMD gunicorn --bind :$PORT --workers 1 --threads 3 main:app --timeout 90

我也面临着同样的问题,终于让它起作用了!这是我的文件:

FROM python:3.7

# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils default-jdk

# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install

# Install Python dependencies.
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

# Copy local code to the container image.
WORKDIR /app
COPY . .
CMD gunicorn --bind :$PORT --workers 1 --threads 3 main:app --timeout 90

非常感谢。这解决了将新构建部署到云运行的问题。但是,我尝试的修复程序没有起作用,因为
WebDriverException:Message:'chromedriver'可执行文件需要在路径中。
仍在继续。知道如何修复吗?您应该在Dockerfile中添加此选项:#安装Python依赖项副本。//运行apk更新运行apk添加卷曲运行apk添加解压缩nano bash Chrome Chrome Chrome Chrome Chrome驱动程序,因为似乎找不到Chrome驱动程序。谢谢!这解决了将新构建部署到云运行的问题。但是,我尝试的修复程序没有起作用,因为
WebDriverException:Message:'chromedriver'可执行文件需要在路径中。
仍在继续。你知道如何修复吗?你应该在Dockerfile中添加这个:#安装Python依赖项副本。//运行apk更新运行apk添加curl运行apk添加解压nano bash Chrome Chrome Chrome Chrome Chrome Chrome Chrome Chrome Chrome Driver,因为似乎找不到Chrome Driver。你最终找到解决方案了吗?我也在做同样的事情。不,我找不到解决这个问题的办法。据我所知,我的选择是要么使用pupeter库在nodejs中编写脚本,要么获得一个虚拟机并在其上安装selenium。我最终在谷歌计算引擎上得到了一台虚拟机,并与之合作。你最终找到了解决方案吗?我也在做同样的事情。不,我找不到解决这个问题的办法。据我所知,我的选择是要么使用pupeter库在nodejs中编写脚本,要么获得一个虚拟机并在其上安装selenium。最后,我在谷歌计算引擎上得到了一台虚拟机,并开始使用它。