undetected-chromedriver
undetected-chromedriver copied to clipboard
OSError: [WinError 6] The handle is invalid
Any idea how to fix this? I tried messing around the init but nothing changed
Try to specify the path of chromedriver.
Try to specify the path of chromedriver.
still wont work
driver = uc.Chrome(options=options, use_subprocess=False)#"use_subprocess" set false
~~~
driver.close() #last line
The same issue, I thought it was Windows Defender Firewall
, but even after adding a path exception for the virtualenv
it still rejected it (I ran the script in the pipenv
). The Run as Administrator
didn't work either. Not using add_experimental_option
also didn't help. I gave up and simply used WSL
Ubuntu
on Windows
. I had so many cases with Windows
with their permissions that in my assumptions if you do not have to use it's not worth grey hair. Not sure if it is solving the problem or a way around it.
Hi. I faced the same problem. Solution: in the \undetected_chromedriver_init_.py file, line 798 was changed to the following form:
try:
time.sleep(0.1)
except OSError:
pass
The code below will cause this behavior:
from selenium import webdriver
import undetected_chromedriver as uc
l = [uc.Chrome() for i in range(3)]
[driver.get('https://www.example.com') for driver in l]
input('...')
l.clear()
If you use selenium.webdriver instead of 'uc', the exception disappears:
l = [uc.Chrome() for i in range(3)]
-> l = [webdriver.Chrome() for i in range(3)]
I found that if you get this WinError 6
exception, it doesn't actually delete temporary files from C:\Users\pc\AppData\Local\Temp. Therefore, to avoid this, you should close your browsers first:
import undetected_chromedriver as uc
l = [uc.Chrome() for i in range(3)]
[driver.get('https://www.example.com') for driver in l]
input('...')
[driver.close() for driver in l]
input('...')
l.clear()
Actually, the reason the exception disappears is because of input('...'), which makes a small pause between closing chrome (it will close if there is one tab left in the browser) and deletion. This seems to be working fine:
import undetected_chromedriver as uc
import time
l = [uc.Chrome() for i in range(3)]
[driver.get('https://www.example.com') for driver in l]
input('...')
for driver in l[:]:
driver.close()
time.sleep(0.1)
l.remove(driver)