![](/img/trans.png)
[英]ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host=u'localhost', port=9200): Read timed out. (read timeout=10))
[英]HTTPConnectionPool(host='localhost', port=4444)
我需要在 docker 容器中運行我的腳本
version: "3"
services:
chrome:
image: selenium/node-chrome:4.0.0-rc-1-prerelease-20210823
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
ports:
- "6900:5900"
selenium-hub:
image: selenium/hub:4.0.0-rc-1-prerelease-20210823
container_name: selenium-hub
ports:
- "4444:4444"
app:
build:
context: .
volumes:
- . :/home/saimon/
network_mode: "host"
depends_on:
- selenium-hub
- chrome
command:
python3 app.py
environment:
- SELENIUM_REMOTE_HOST=selenium-hub
在我的應用程序中我:
driver = webdriver.Remote(command_executor='http://selenium-hub:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME, options=self.chrome_options)
我制作:docker-compose 構建
sudo docker-compose run --rm app 或 docker-compose -f docker-compose.yml up
並顯示此錯誤:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='selenium-hub', port=4444): Max retries exceeded with url: /wd/hub/session (由 NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa7f86b3700>:無法建立新連接:[Errno -3] 名稱解析暫時失敗'))
如果您希望能夠從應用程序容器連接到http://selenium-hub:4444
,請刪除network_mode: "host"
您還應該嘗試使用 env-var
import os
host = os.environ['SELENIUM_REMOTE_HOST']
driver = webdriver.Remote(command_executor='http://{}:4444/wd/hub'.format(host),
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.