创建新的chromedriver实例(在python中):webdriver.Chrome("./venv/selenium/webdriver/chromedriver")
时,出现错误http.client.BadStatusLine: ''
。我没有导航到网站,或使用服务器,只是创建一个新的chromedriver。我在VirtualEnv中拥有最新版本的Selenium(3.0.1)和chromedriver(2.24.1)。这几天前工作正常,我没有更改任何代码。我不确定从哪里开始解决代码问题。我的第一步是运行pip install --upgrade -r requirements.txt
以确保所有包都是最新的。我现在唯一的想法是selenium没有处理默认的起始页面,其中url为data;,
,因为没有响应。但是,由于这是默认行为,如果selenium无法处理其自己的默认行为,我会感到惊讶。任何帮助将不胜感激!
当代码运行时(通过来自bash终端的python),成功创建了一个新的chromedriver实例,但错误http.client.BadStatusLine: ''
被抛出,并且python终端失去了与chromedriver的连接。
完整代码:
import pythonscripts
# Creates a new webdriver
driver = pythonscripts.md()
# Never gets here, attempts to use driver get NameError: name 'driver' is not defined
Pythonscripts md方法:
def md():
return webdriver.Chrome("./venv/selenium/webdriver/chromedriver")
完整错误输出:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/brydenr/server_scripts/cad_tests/pythonscripts.py", line 65, in md
return webdriver.Chrome("./venv/selenium/webdriver/chromedriver")
File "/Users/brydenr/server_scripts/venv/lib/python3.4/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/Users/brydenr/server_scripts/venv/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Users/brydenr/server_scripts/venv/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/Users/brydenr/server_scripts/venv/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "/Users/brydenr/server_scripts/venv/lib/python3.4/site-packages/selenium/webdriver/remote/remote_connection.py", line 407, in execute
return self._request(command_info[0], url, body=data)
File "/Users/brydenr/server_scripts/venv/lib/python3.4/site-packages/selenium/webdriver/remote/remote_connection.py", line 439, in _request
resp = self._conn.getresponse()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 1171, in getresponse
response.begin()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 351, in begin
version, status, reason = self._read_status()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 321, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: ''
尝试做
try:
webdriver.Chrome("./venv/selenium/webdriver/chromedriver")
except Exception:
webdriver.Chrome("./venv/selenium/webdriver/chromedriver")
结果是两个与之前相同的回溯,以及两个chromedriver实例。好像question指向urllib
中的错误,但情况略有不同。
答案 0 :(得分:1)
在我将chrome更新到最新版本之后发生了这种情况。 我刚刚将chromedriver更新为2.25,它再次有效。