Python + Splinter:错误 - httplib.BadStatusLine:''
Posted
技术标签:
【中文标题】Python + Splinter:错误 - httplib.BadStatusLine:\'\'【英文标题】:Python + Splinter: Error - httplib.BadStatusLine: ''Python + Splinter:错误 - httplib.BadStatusLine:'' 【发布时间】:2017-09-24 18:41:45 【问题描述】:在我的 python 项目中,我使用 Splinter (https://splinter.readthedocs.io/en/latest/) 打开浏览器并尝试访问一个站点:
from splinter import Browser
browser = Browser('chrome')
browser.visit('http://www.google.com')
浏览器打开,无法访问http://www.google.com
,出现如下错误:
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: ''
奇怪的是,它可以在另一台 Mac 计算机上运行,但是当我将它转移到另一台 Mac 计算机时,遇到了该错误。
四处研究,但无法弄清楚真正的问题是什么。我可能做错了什么?我应该如何解决这个问题?
提前谢谢你,一定会支持/接受答案
【问题讨论】:
您是否验证了失败的 Mac 电脑上的 chromedriver 版本? @gipsy 我该怎么做?我应该寻找什么? 【参考方案1】:您所描述的症状指向 过时的 chromedriver。转到"ChromeDriver Downloads" 页面并下载最新的驱动程序。对于当前最新的稳定版 Chrome 58,您需要 chromedriver
2.29。
请注意,要检查chromedriver
版本,请执行:
$ chromedriver --version
另外,请确保您拥有最新的 splinter
和 selenium
:
$ pip install -U splinter selenium
【讨论】:
感谢您的回复。有没有办法通过终端安装最新的chromedriver
?因为如果我手动进行,设置路径似乎有问题。
@JoKo 没有尝试过,但看起来有this option。谢谢。
仍有问题。我检查了 chromedriver 版本,它是 2.22。尝试安装,它一直说我有 chromedriver 2.22,并按照建议更新了 splinter/selenium,但仍然出现相同的错误...以上是关于Python + Splinter:错误 - httplib.BadStatusLine:''的主要内容,如果未能解决你的问题,请参考以下文章
Python + requests + splinter:发出多个并发“get”请求的最快/最佳方法是啥?
Python3.4:splinter or traceback
微软又出现好玩的了,Python 录制自动化操作,自动生成代码