NS_ERROR_SOCKET_ADDRESS_IN_USE

问题描述 投票:4回答:1

我的代码:

from selenium import webdriver
import selenium.webdriver.support.ui as ui
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()
driver.get("https://www.youtube.com")
login_wait = WebDriverWait(driver, 10)

textbox = login_wait.until(EC.visibility_of_element_located((By.ID, 'search')))
textbox.send_keys("a")

time.sleep(10)
driver.close()

Python控制台中没有错误,但是geckodriver.log:

1514074507756   geckodriver INFO    geckodriver 0.19.1
1514074507763   geckodriver INFO    Listening on 127.0.0.1:49865
1514074508870   mozrunner::runner   INFO    Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-profile" "/var/folders/kf/8800phd97vx28vtzdytqk1m80000gn/T/rust_mozprofile.oI7AzEUKweAr"
1514074509913   Marionette  ERROR   Error on starting server: [Exception... "Component returned failure code: 0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]"  nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)"  location: "JS frame :: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 95"  data: no]
[Exception... "Component returned failure code: 0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]"  nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)"  location: "JS frame :: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 95"  data: no]
MarionetteServer.prototype.start@chrome://marionette/content/server.js:95:19
MarionetteComponent.prototype.init@jar:file:///Applications/Firefox.app/Contents/Resources/omni.ja!/components/marionette.js:217:5
MarionetteComponent.prototype.handle@jar:file:///Applications/Firefox.app/Contents/Resources/omni.ja!/components/marionette.js:112:5

2017-12-23 19:15:11.556 plugin-container[42994:4077314] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x9b3b, name = 'com.apple.tsm.portname'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2017-12-23 19:15:11.559 plugin-container[42994:4077314] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x9e03, name = 'com.apple.CFPasteboardClient'
See /usr/include/servers/bootstrap_defs.h for the error codes.
selenium firefox selenium-webdriver geckodriver
1个回答
1
投票

如果查看错误堆栈跟踪,错误会说明一切:

1514074509913   Marionette  ERROR   Error on starting server: [Exception... "Component returned failure code: 0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]"  nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)"  location: "JS frame :: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 95"  data: no]

这基本上意味着Marionette试图通过端口localhost打开你127.0.0.149865的连接,但由于以下原因之一,该端口目前被占用:

  • Port 49865目前正在被你的localhost用完的其他一些应用程序使用。
  • 从你的Port 49865运行的某些服务使用localhost
  • Port 49865尚未被WebDriver变种的悬空实例释放,例如GeckoDriverChromeDriverIEDriverServerGhostDriver

方案:

解决方案将是/以下所有步骤:

  • 始终在你的driver.quit()tearDown()方法中使用Automation Script。如果任何WebDriver变种的悬空实例,例如GeckoDriverChromeDriverIEDriverServerGhostDriver存在于您的系统中,以编程方式/手动方式杀死它们。
  • 确保Port 49865不会被任何其他用完localhost的应用程序使用。
  • 确保从Port 49865运行的某些服务不使用localhost
  • 在执行CCleaner之前和之后使用Tests工具擦除系统中的OS杂务。
  • 拿一个System Reboot
  • 如果问题仍然存在,uninstall Mozilla Firefox Browser通过Revo Uninstaller并安装新的Mozilla Firefox Browser实例
© www.soinside.com 2019 - 2024. All rights reserved.