2
votes
  • ENV

    PhantomJS2.1.1;Windows10;selenium-3.8.0;python3

  • CODE

    browser = webdriver.PhantomJS() //throw a UnicodeDecodeError   
    
  • Problem

    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 2: invalid start byte

  • Details

    Traceback (most recent call last): File "d:/devtools/phantomjs-2.1.1-windows/bin/IndustryLeaderSpider.py", line 20, in browser = webdriver.PhantomJS('D:/phantomjs.exe') File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 58, in init desired_capabilities=desired_capabilities) File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in init self.start_session(desired_capabilities, browser_profile) File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 309, in execute response = self.command_executor.execute(driver_command, params) File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 460, in execute return self._request(command_info[0], url, body=data) File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 522, in _request resp = opener.open(request, timeout=self._timeout) File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 526, in open response = self._open(req, data) File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 544, in _open '_open', req) File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 504, in _call_chain result = func(*args) File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 806, in meth(r, proxy, type)) File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 814, in proxy_open if req.host and proxy_bypass(req.host): File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 2739, in proxy_bypass return proxy_bypass_registry(host) File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 2706, in proxy_bypass_registry fqdn = socket.getfqdn(rawHost) File "D:\Continuum\Anaconda3\lib\socket.py", line 673, in getfqdn hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 2: invalid start byte


Do someone have this problem? How to fix it?

1

1 Answers

0
votes

Your main error seems to be :

File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 460, in execute return self._request(command_info[0], url, body=data) File "D:\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 522, in _request resp = opener.open(request, timeout=self._timeout) File "D:\Continuum\Anaconda3\lib\urllib\request.py", line 526, in open response = self._open(req, data)

Try the following steps :

  • Run CCleaner tool to wipe off all the OS chores.
  • Take a System Reboot.
  • While you initiate PhantomJS() provide the absolute path of the phantomjs binary as follows :

    driver = webdriver.PhantomJS(executable_path=r'C:\path\to\phantomjs.exe')
    
  • Ensure that there is no unnecessary imports in your script. Example : urllib.request

  • Execute your Test.