Python + Splinter: Error - httplib.BadStatusLine: ''
Asked Answered
M

1

7

In my python project, I'm using Splinter (https://splinter.readthedocs.io/en/latest/) to open a browser and attempt visit a site:

from splinter import Browser

browser = Browser('chrome')
browser.visit('http://www.google.com')

And the browser opened up, and without being able to visit http://www.google.com, it got the following error:

Traceback (most recent call last):
  File "practice.py", line 90, in <module>
    browser = Browser('chrome')
  File "/Library/Python/2.7/site-packages/splinter/browser.py", line 63, in Browser
    return driver(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/splinter/driver/webdriver/chrome.py", line 31, in __init__
    self.driver = Chrome(chrome_options=options, **kwargs)
  File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 98, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 185, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 247, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/remote_connection.py", line 464, in execute
    return self._request(command_info[0], url, body=data)
  File "/Library/Python/2.7/site-packages/selenium-3.4.0-py2.7.egg/selenium/webdriver/remote/remote_connection.py", line 488, in _request
    resp = self._conn.getresponse()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1132, in getresponse
    response.begin()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 417, in _read_status
    raise BadStatusLine(line)
httplib.BadStatusLine: ''

Weirdly, it works on a different Mac computer, but when I transferred it to another Mac computer, encountered that error.

Researched around but could not make out what the real problem is. What could I be doing wrong? And how should I go about resolving the issue?

Thank you in advance and will be sure to upvote/accept answer

Misbegotten answered 27/4, 2017 at 6:7 Comment(2)
Have you verified the chromedriver version on the Mac computer where it failing?Monecious
@Monecious How can I do so? And what should I be looking for?Misbegotten
V
0

The symptoms you are describing point to the outdated chromedriver. Go to the "ChromeDriver Downloads" page and download the latest driver. For the currently latest stable Chrome 58, you need chromedriver 2.29.

Note that to check the chromedriver version, execute:

$ chromedriver --version

And, also, make sure you have the latest splinter and selenium:

$ pip install -U splinter selenium
Vitriol answered 6/5, 2017 at 16:57 Comment(3)
Appreciate your response. Is there a way to install the latest chromedriver via terminal? Because if I do it manually, there seem to be an issue with setting up the path.Misbegotten
@JoKo have not tried that, but it looks like there is this option. Thanks.Vitriol
still having trouble. I checked the chromedriver version and it was 2.22. Tried installing and it keeps saying I have chromedriver 2.22, and updated both splinter/selenium as suggested yet still getting the same error...Misbegotten

© 2022 - 2024 — McMap. All rights reserved.