2

I am studying Python with the book "Automate the boring stuff with Python" (written by Al Sweigart) and I have a problem with web scraping (Chapter 11), namely the selenium module. I am writing the following in Python IDLE:

>>> from selenium import webdriver
>>> browser = webdriver.Firefox() # Here Windows command black window appears
                                  # and Mozilla Firefox with blank page opens
>>> browser.get('http://inventwithpython.com')
    Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    browser.get('http://inventwithpython.com')
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 326, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 495, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1065, in _send_output
    self.send(chunk)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 986, in send
    self.sock.sendall(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

>>> browser.get('http://inventwithpython.com')

When I write >>> browser.get('http://inventwithpython.com') the first time, the error occurs. When I write this command the second time, the Mozilla Firefox browser opens desired web page. When I write the command the third time, the ConnectionAbortedError again occurs, and so on - the odd times of writing the command (1, 3, ...) result in the ConnectionAbortedError, and the even times (2, 4, ...) pass without error. I tried to turn off antivirus and firewall but it did not help. Please help me with the issue. P.S. I have Windows 10 OS.

Leonid
  • 35
  • 6
  • I am 99% sure this has nothing to do with IDLE, and hence removed the tag. To be 100% sure, run interactive python from command prompt or Start menu, 'Python 3.6', under 'Python 3.6' and give the same commands. If I am wrong, add 'Python-IDLE' back and please lease a comment addressed to me. Sorry, but I don't know anything about selenium. – Terry Jan Reedy Jul 04 '18 at 03:01
  • I tried to give the same commands in command window (Windows 10 PowerShell) under Python 3.6.5. The result is the same as was in Python IDLE. – Leonid Jul 04 '18 at 09:04
  • Thank you for the feedback. Too many people never respond to comments. – Terry Jan Reedy Jul 05 '18 at 20:29

1 Answers1

3

I'm the author of Automate the Boring Stuff with Python. I encountered this error as well on a Windows 10 machine. According to this StackOverflow answer https://stackoverflow.com/a/51005821/1893164 this seems to be a problem with geckodriver 0.21.0.

The workaround which worked for me was to install the older version of geckodriver, 0.20.1, which you can download here: https://github.com/mozilla/geckodriver/releases/tag/v0.20.1

Al Sweigart
  • 11,566
  • 10
  • 64
  • 92
  • Thank you very much for reply! I downloaded geckodriver 0.20.1, then I put it in C:\Users\User\AppData\Local\Programs\Python\Python36-32\selenium\webdriver folder. Then I added this folder to system environment variables list. The following code worked without errors: `>>> from selenium import webdriver` `>>> browser = webdriver.Firefox()` `>>> browser.get('http://inventwithpython.com')` – Leonid Jul 10 '18 at 11:28