python - 当我尝试通过 Python 远程连接到 selenium 网格时获取 404 on/wd/hub/session

标签 python selenium selenium-webdriver selenium-grid

我可以在控制台下看到两个 Remote ,但是当我尝试远程连接并执行某些操作时,它失败并显示 404。

from selenium import webdriver
browser = webdriver.Remote(
   command_executor='http://ec2-184-72-129-183.compute-1.amazonaws.com:4444/wd/hub',
   desired_capabilities={'browserName': 'firefox'})
browser.get('http://www.google.com')
browser.quit()

抛出这个异常

Traceback (most recent call last):
  File "browser-shot.py", line 16, in <module>
    desired_capabilities={'browserName': 'firefox'})
  File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 62, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 104, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 155, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 125, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: '<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>\n<title>Error 404 </title>\n</head>\n<body><h2>HTTP ERROR: 404</h2><pre>NOT_FOUND</pre>\n<p>RequestURI=/wd/hub/session</p><p><i><small><a href="http://jetty.mortbay.org/">Powered by Jetty://</a></small></i></p><br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n<br/>                                                \n\n</body>\n</html>\n' 

最佳答案

这似乎不是 Python 错误。看起来您拥有 selenium 服务器的机器正在拒绝请求。 在错误消息中,您有一个 <a href="http://jetty.mortbay.org/">Powered by Jetty://</a> 这让我想到它与 Jetty 有某种关系。

我对 Jetty 了解不多,但您可能想在那里寻找答案。 一个可能的问题是 Jetty 也在端口 4444 上运行,但我不能肯定地说,因为我不知道 Jetty 是如何工作的。

编辑

我还应该补充一点,我在我的本地机器上尝试了您的设置,到我的一台服务器(上面没有 Jetty)并且它运行得非常好。

关于python - 当我尝试通过 Python 远程连接到 selenium 网格时获取 404 on/wd/hub/session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11208040/

相关文章:

python - 有没有更好的方法(比通过变量)来查找循环 block 是否被执行(即使一次)?

python - 更新 PySDL2 中的窗口位置(帮助!)

当从未调用 issubclass() 时,Python 在 issubclass() 上抛出 TypeError

java - Selenium java无法获取html文本

python - 当选择标签样式属性设置为显示: none; in python selenium时如何从下拉列表中检索值

java - webdriver 是类还是接口(interface)?

python - ssh paramiko 无法读取输出

python - python Selenium 包中的格式错误

python - 在python中通过Selenium Webdriver下载文件

java - Selenium Webdriver 和 Firefox Server Not Found 错误