Python selenium: WinError 10053 - host is shutting connection down - python

I started messing around with Python networking using selenium on Firefox. Unfortunately, I keep getting "ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine".
However, this only happens when running some commands, and it only happens the first time I run them. If execute the command a second time right after that, it works. (See below for a minimal example.)
I found this question, but being a networking newbie I'm having a hard time applying the solution to my situation. How do I prevent the connection from shutting down?
Any help is greatly appreciated!
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com/')
searchfield = browser.find_element_by_id("lst-ib") # Runs without issues
searchfield.get_attribute("value") # Produces WinError 10053
searchfield.get_attribute("value") # Returns '' as it should
EDIT: It seems the error only occurs, when I execute the command in the shell, rather than saving and running the whole script. Nonetheless, it's pretty annoying.

I got the same problem, my config is:
Firefox 60.0.2 (64 bits)
; geckodriver 0.21.0 ( 64 bits)
; selenium 3.12.0
I resolved this problem by downgrade geckodriver to 0.20.1 ( 64 bits)

I had the same problem and tried solutions that were mentioned here but nothing helped me. In the end, it was a very simple solution:
copy the script and the geckodriver to a different folder, and then run it from there. I suppose that in the folder where I always worked I had logs that generated conflicts and that's why this solution worked.

Related

bluetooth_adapter_winrt.cc:715 GetBluetoothAdapterStaticsActivationFactory failed [duplicate]

I have updated Selenium but the error keeps occurring even though the web page loads. However, in some instances, the driver starts but it is stagnant. Is this causing an issue and if so, how do I resolve it?
[11556:9032:0502/152954.314:ERROR:device_event_log_impl.cc(162)] [15:29:54.314] Bluetooth: bluetooth_adapter_winrt.cc:1055 Getting Default Adapter failed.
This error message...
ERROR:device_event_log_impl.cc(162)] [15:29:54.314] Bluetooth: bluetooth_adapter_winrt.cc:1055 Getting Default Adapter failed.
...implies that ScopedClosureRunner on_init failed in BluetoothAdapterWinrt::OnGetDefaultAdapter().
Analysis
This error is defined in bluetooth_adapter_winrt.cc as follows:
void BluetoothAdapterWinrt::OnGetDefaultAdapter(
base::ScopedClosureRunner on_init,
ComPtr<IBluetoothAdapter> adapter) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (!adapter) {
BLUETOOTH_LOG(ERROR) << "Getting Default Adapter failed.";
return;
}
Solution
Ensure that:
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v84.0 level.
Chrome is updated to current Chrome Version 84.0 level. (as per ChromeDriver v84.0 release notes)
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Additional considerations
However it was observed that this error can be supressed by running Chrome as root user (administrator) on Linux. but that would be a deviation from the documentation in ChromeDriver - WebDriver for Chrome where it is mentioned:
A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing '--no-sandbox' flag when creating your WebDriver session, i.e. the ChromeDriver session as such a configuration is unsupported and highly discouraged.
Ideally, you need to configure your environment to run Chrome as a regular user instead.
Suppressing the error
Finally, as per the documentation in Selenium Chrome Driver: Resolve Error Messages Regarding Registry Keys and Experimental Options these error logs can be supressed by adding the argument:
excludeSwitches: ['enable-logging']
So your effective code block will be:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.google.com/")
I had simmilar problems
ConnectionResetError: [WinError 10054] An existing connection was
forcibly closed by the remote host and
Bluetooth: bluetooth_adapter_winrt.cc:1055 Getting Default Adapter
failed.
Both of them disapeared after running cmd as an administrator. I don't know what is the exact cause of this issue but for me it seems that's a lack of privs while running selenium.
If anyone could explain why it is happening would be great.
Simply switching on my device's Bluetooth solved the problem... Don't know the reason behind it
I was getting the same error. On a code that was working yesterday.
The Code is available at this url at this moment https://youtu.be/0kLoVGLTISg?list=PLUDwpEzHYYLvx6SuogA7Zhb_hZl3sln66&t=4073
https://github.com/Microsoft/vscode-python/issues/3252 Found the Resolution hint over here in the comments section, along with https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUp,
suggesting that, we cannot run on "Pycharm"/VSCode using right click -> run from within the class level, we need to run it from the module level i.e. outside the class level, since setUpClass() method is not executed when running from inside of the class.

VSCode Python SSH - Debug aborted without errors or warnings

I am developing an application on a remote server.
I'm using Python and am connected via ssh with the specific extension.
I start debugging and everything seems to proceed normally but suddenly debugging stops and there is no reason (error or warning).
Can anyone suggest me where to look for the reason or how to trace the problem?
The script, executed outside VSCode, runs smoothly.
Thanks in advance.
in the end I found a possible cause and, therefore, the solution.
There is a problem with the sequence of imports and module import for MariaDB. By moving this import to the head, the problem was solved.

I'm trying to start the chrome webdriver on linux, but it hangs, then closes

I'm making a program with selenium (python). It was working, and out of nowhere, the webdriver no longer works. I'm developing on a windows environment (and it works fine), but once I upload the code to the production server (Ubuntu), I try to open the web driver and it only displays data;, the driver hangs, then closes. No code after that continues.
Example:
print("Starting web driver")
driver = webdriver.Chrome(driver_path, options=opt)
print("Opening URL") # This code doesn't run
driver.get(config.url) # This code doesn't run
Things I've tried:
Running it on Windows (it works properly)
Updating the webdriver
Running it outside of the venv
Running the driver in a new, isolated environment
Wrapping the entire code within try-except (no errors output)
Running with the argument --headless
Edit: I'm running python3.7, chrome webdriver V 75.0.3770.90
Edit2: the driver_path var is the relative path to the chromedriver file. The opt are my list of chrome options:
opt = Options()
opt.add_argument('--no-sandbox')
opt.add_argument('--disable-dev-shm-usage')
profile = {"plugins.always_open_pdf_externally": True,
"download.default_directory": download_directory,
"download.prompt_for_download": False,
"download.directory_upgrade": True}
opt.add_experimental_option("prefs", profile)
I'm also using gunicorn as my webserver, but running it with the default (flask) webserver, I still encounter the issue. I'm also executing functions I've written for selenium through a flask-based web application (its a web app for work) The ubuntu machine that's running the script has a desktop environment installed.
After 15-25 seconds, the windows closes with no output in the terminal. After ~90 seconds, I get a message in the terminal saying:
Message: session not created
from disconnected: unable to connect to renderer
(Session info: chrome=75.0.3770.90)
I've also noticed that the chrome driver takes more time to open than usual.
Edit3: I've literally deleted then entire virtual machine and reinstalled it from scratch, and I'm still running into the same issue, I've reverted to an older version and it still doesn't run, which makes no logical sense. My only thought is that there is some configuration error or that something is interfering with it.
Edit4: I was able to get the log from the webdriver by adding the argument --verbose
Heres the log:
[1562179109.454][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1562179111.454][WARNING]: Timed out connecting to Chrome, retrying...
[1562179111.454][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1562179115.454][WARNING]: Timed out connecting to Chrome, retrying...
[1562179115.455][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1562179123.454][WARNING]: Timed out connecting to Chrome, retrying...
[1562179123.455][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1562179139.455][WARNING]: Timed out connecting to Chrome, giving up.
[1562179139.506][INFO]: [42e538ee02eb06b9ac776969dddf01d1] RESPONSE InitSession ERROR session not created
from disconnected: unable to connect to renderer
(Session info: chrome=75.0.3770.90)
[1562179139.506][DEBUG]: Log type 'driver' lost 9 entries on destruction
[1562179139.506][DEBUG]: Log type 'browser' lost 0 entries on destruction
I'm not too familiar with Linux, but from what I've seen in the past, I have a feeling its something to do with /etc/hosts (idk?)
Edit5:
I've noticed this started happening after I installed windscribe (vpn) which makes me think that windscribe is interfering with the connection somehow.
I turns out, windscribe (vpn) interferes with the connection to the chrome webdriver, I believe it has something to do with its built-in firewall, after uninstalling it, calling sudo apt autoremove -y and a reboot, it works properly!
Edit: I re-installed the VPN (windscribe) and de-activated the included firewall and it worked properly after that.

Permission denied when trying to open Firefox to run Selenium tests via Django's manage.py

I'm running on Ubuntu 16.04.
I've been dealing with this issue for a while now, and I have not been able to find a solution on my own. When I run python3 manage.py test, my tests are to open a Firefox browser via Selenium and execute some functional tests. I get the same error message on every test I try to run;
selenium.common.exceptions.WebDriverException: Message: Failed to start browser /home/spa/Desktop/firefox: permission denied
I have tried to do chmod a+rwx on the firefox folder, but I still get the same error. Attempting to sudo python3 manage.py test results in the same issue. Any help would be appreciated.
I have had a similar problem on my Mac when starting firefox using a binary path. What i did to fix it is, i gave the binary path to the exact file needed to start firefox (usually a shell script inside the firefox folder)
There have been some problems with opening browsers from folders as seen here so this was the only way I found how to fix the problem.
There is also 1 more reason i could think of, why it would not work, there might be an incompatibility between your selenium and the firefox you are using. What is the version and what's the actual code you use?

Python - Selenium error on Ubuntu

I've a strange problem with Python (or maybe I'm only a noob).
I wrote a little bot to automate some action on the browser using selenium and I want to run on a Ubuntu VPS, so I've installed Selenium and the other modules I needed and I ran the script but when it comes to the first of this lines
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "free_play_captcha_types")))
driver.find_element_by_id("free_play_captcha_types").click()
driver.find_element_by_id("free_play_captcha_types").click()
driver.find_element_by_xpath("//option[contains(#value, 'recaptcha_v1')]").click()
I get the socket.error: errno [111] Connection refused error.
I've already tried to run the selenium server before running the script but nothing changes... has someone have an advice?
Thank you in advance.
Another information: I ran the same script on a different VPS and it ran successfully...

Categories