4

I am trying to use selenium on Windows. Whenever I run this code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
path = "C:/Users/User/Webdriver/chromedriver.exe"

driver = webdriver.Chrome(chrome_options=options, executable_path=path)
driver.get("http://www.python.org")

I get the following error. I don’t really understand the problem. I am not using a proxy or anything like that. Therefore I don't think it is related to my network but I could be completely wrong.

in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: <HTML><HEAD>
<TITLE>Network Error</TITLE>
</HEAD>
<BODY>
<FONT face="Helvetica">
<big><strong></strong></big><BR>
</FONT>
<blockquote>
<TABLE border=0 cellPadding=1 width="80%">
<TR><TD>
<FONT face="Helvetica">
<big>Network Error (dns_unresolved_hostname)</big>
<BR>
<BR>
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
Your requested host "localhost" could not be resolved by DNS.
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">

</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica" SIZE=2>
<BR>
For assistance, contact your network support team.
</FONT>
</TD></TR>
</TABLE>
</blockquote>
</FONT>
</BODY></HTML>```
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Brian Hode
  • 75
  • 1
  • 5
  • How _certain_ are you that you're not using a proxy? Are you using a corporate computer or a personal one? Can you provide the traceback? Is the error happening on the last line or before that? – sytech Feb 23 '22 at 09:11
  • Do you get anything different if you use https, i.e. https:// www .python.org – PangolinPaws Feb 23 '22 at 09:11
  • @PangolinPaws No it doesn’t change anything when I use a different website. – Brian Hode Feb 23 '22 at 09:18
  • @sytech It happens at the line: `driver = webdriver.Chrome(options=options, executable_path=path,desired_capabilities=capabilities)` – Brian Hode Feb 23 '22 at 09:19
  • @BrianHode try without passing `options` or `desired_capabilities`. Do you get the same error? I would also double-check the version of chrome you are using and that it matches your chromedriver version... another thought... `localhost` should be in your system's `hosts` file. Your browser shouldn't even be trying to do DNS lookups. Is it possible you've removed `localhost` from your `hosts` file? – sytech Feb 23 '22 at 09:26
  • @sytechMy chrome version matches my web driver, localhost is in contained my hosts file – Brian Hode Feb 23 '22 at 10:00
  • I also tried switching my driver to Firefox but the same error occurs – Brian Hode Feb 23 '22 at 10:03

1 Answers1

0

This error message...

Your requested host "localhost" could not be resolved by DNS

...implies that as per the DNS entries localhost wasn't resolved properly.

Ensure that hosts file have the following entries:

127.0.0.1      localhost

Incase you are behind a proxy, you may like to:

  • Remove the proxy settings temporarily.
  • Ensure localhost is resolved by DNS.
  • Set up the proxy again.

You can find a detailed discussion in Apache: Your requested host "localhost" could not be resolved by DNS


tl; dr

hosts file ignored, how to troubleshoot?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352