Home > Software engineering >  Selenium WebDriverException when self.driver_.get("http://www.stockbroking.com.my")
Selenium WebDriverException when self.driver_.get("http://www.stockbroking.com.my")

Time:10-27

I have a Ken**** stock buying bot (Ken**** is a stockbroking firm) dubbed "Kenbot" that have been running for a year now which I have spent most of the time trying to iron out the bugs. Until recently, I have a new traceback that I am stumped on. It only occurs occasionally on some days and not on others.

Kenbot runs via my Synology NAS on a docker image (selenium/standalone-chrome:latest) every morning before the market opens it will place orders for few stocks. It works via Selenium.

Right now I have no solution beyond having a @retry decorator that will reattempt to place stock orders if WebDriverException is encountered.

How do I go about fixing this issue?

Traceback (most recent call last):
  File "/volume1/homes/admin/Drive/stock/order/downloadContractNote.py", line 23, in main
    with docker_selenium() as _, Kenbot(headless=True) as bot:
  File "/volume1/homes/admin/Drive/stock/logs/logger.py", line 58, in wrapper
    return func(*args, **kwargs)
  File "/volume1/homes/admin/Drive/stock/order/kenbot.py", line 100, in __init__
    self.bot.login()
  File "/volume1/homes/admin/Drive/stock/order/kenbot.py", line 70, in f_retry
    return f(*args, **kwargs)
  File "/volume1/homes/admin/Drive/stock/order/kenbot.py", line 176, in login
    self.driver_.get("http://www.stockbroking.com.my")
  File "/volume1/homes/admin/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/volume1/homes/admin/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/volume1/homes/admin/venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_NAME_NOT_RESOLVED
  (Session info: headless chrome=94.0.4606.81)

CodePudding user response:

Presumed you are using docker-compose, you can add the IP of www.stockbroking.com.my:

...
services:
  <app>:    
    extra_hosts:
    - "www.stockbroking.com.my:<add IP address here>"
...

Or, docker run --add-host www.stockbroking.com.my:<add IP address here> ...

Or using Python docker SDK as illustrated in the comment:

container = client.containers.run('selenium/standalone-chrome', user = 'root', detach=True, auto_remove=True, environment = ["TZ=Asia/Kuala_Lumpur"], ports={'4444/tcp':('127.0.0.1',4444)}, extra_hosts={'www.stockbroking.com.my': '999.99.99.999'}, privileged = True)

  • Related