Open evolvepx opened 1 year ago
Same here... Been having it now and then for a few weeks, was too lazy to try and fix it, but now it kinda starts being annoying having to restart scripts all day.
Edit: As it's probably a problem with subprocessing it might have already gotten resolved with v3.1.7 Let's see if I get any crashes until tomorrow morning...
Just got this error today. Also, it took a ridiculously long time to load up the browsers. Probably over a minute each. I don't get this issue with firefox as the webdriver.
modify
import undetected_chromedriver as uc
to
import undetected_chromedriver.v2 as uc
Thought it got solved, but just had a crash again... Updating to 3.1.7 did not resolve the issue, neither did what @evolvepx proposed (to add ".v2" in the import).
I'll attach the console output below. The crash was caused by this line: driver = uc.Chrome(version_main=installed_chromeVersion, options=chrome_options)
Traceback (most recent call last):
File "C:\Users\timbe\Desktop\ProjectFolder\ScriptTitle.py", line 410, in <module>
driver = uc.Chrome(version_main=installed_chromeVersion, options=chrome_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 429, in __init__
super(Chrome, self).__init__(
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
super().__init__(
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
super().__init__(
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 715, in start_session
super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:[58561](tel:58561)
from chrome not reachable
Stacktrace:
Backtrace:
(No symbol) [0x0058F243]
(No symbol) [0x00517FD1]
(No symbol) [0x0040CF10]
(No symbol) [0x00402B0A]
(No symbol) [0x0042F04E]
(No symbol) [0x00428424]
(No symbol) [0x00428201]
(No symbol) [0x0045F056]
(No symbol) [0x0045EB2A]
(No symbol) [0x00458386]
(No symbol) [0x0043163C]
(No symbol) [0x0043269D]
GetHandleVerifier [0x00829A22+2655074]
GetHandleVerifier [0x0081CA24+2601828]
GetHandleVerifier [0x00638C0A+619850]
GetHandleVerifier [0x00637830+614768]
(No symbol) [0x005205FC]
(No symbol) [0x00525968]
(No symbol) [0x00525A55]
(No symbol) [0x0053051B]
BaseThreadInitThunk [0x75F000F9+25]
RtlGetAppContainerNamedObjectPath [0x77897BBE+286]
RtlGetAppContainerNamedObjectPath [0x77897B8E+238]
Exception ignored in: <function Chrome.__del__ at 0x000001A6668B3B00>
Traceback (most recent call last):
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
self.quit()
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
time.sleep(0.1)
OSError: [WinError 6] The handle is invalid
Something interesting: The part below was repeated like 20 times.
Exception ignored in: <function Chrome.__del__ at 0x000001A6668B3B00>
Traceback (most recent call last):
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
self.quit()
File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
time.sleep(0.1)
OSError: [WinError 6] The handle is invalid
From Stack Overflow: cannot connect to chrome at 127.0.0.1:37541 when using undetected-chromedriver with Python
It seems like the OSError: [WinError 6] The handle is invalid
has actually nothing to do with the issues themselves and is probably just Windows trying to close down a nonexistent chromedriver session.
In my case I will now try the different solutions from the issues mentioned above for cannot connect to chrome at 127.0.0.1:[58561]
which is the actual issue in my case.
Edit: Merry Christmas everyone :)
Got the same error on version 3.1.7. Even if I change to import undetected_chromedriver.v2 as uc
, the problem still exists.
Got the same error on version 3.1.7. Even if I change to
import undetected_chromedriver.v2 as uc
, the problem still exists.
@chinwubing What's your full console output regarding the error?
i seem to have the same thing tried the .v2 thing but no shot if you read the updates the v2 thing is no longer required its the new v1 ### EDIT: I WAS ABLE TO FIX IT, PYTHON 3.11 WAS THE ISSUE, Running Python 3.9.13 works fine
Exception ignored in: <function Chrome.__del__ at 0x0000024E66570360>
Traceback (most recent call last):
File "C:\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
self.quit()
File "C:\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
time.sleep(0.1)
OSError: [WinError 6] The handle is invalid
Exception ignored in: <function Patcher.__del__ at 0x0000024E6656B7E0>
Traceback (most recent call last):
File "C:\Python311\Lib\site-packages\undetected_chromedriver\patcher.py", line 273, in __del__
time.sleep(0.1)
OSError: [WinError 6] The handle is invalid```
Got the same error on version 3.1.7. Even if I change to
import undetected_chromedriver.v2 as uc
, the problem still exists.@chinwubing What's your full console output regarding the error? This is what I got in the output:
['CDwindow-1366722711AD866B1B8BF5B8A2B1410D'] Exception ignored in: <function Chrome.__del__ at 0x0000027460CFD760> Traceback (most recent call last): File "C:\projects\venv\invest\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__ File "C:\projects\venv\invest\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit OSError: [WinError 6] The handle is invalid
i seem to have the same thing tried the .v2 thing but no shot if you read the updates the v2 thing is no longer required its the new v1 ### EDIT: I WAS ABLE TO FIX IT, PYTHON 3.11 WAS THE ISSUE, Running Python 3.9.13 works fine
Exception ignored in: <function Chrome.__del__ at 0x0000024E66570360> Traceback (most recent call last): File "C:\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__ self.quit() File "C:\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit time.sleep(0.1) OSError: [WinError 6] The handle is invalid Exception ignored in: <function Patcher.__del__ at 0x0000024E6656B7E0> Traceback (most recent call last): File "C:\Python311\Lib\site-packages\undetected_chromedriver\patcher.py", line 273, in __del__ time.sleep(0.1) OSError: [WinError 6] The handle is invalid```
I run Python 3.9 and get the issue.
are you using driver.close() or driver.quit() try changing between them and see if that helps
I'm getting the error with Python 3.9 and 3.11 but for 3.10.7 everything works fine
Same issue. Just testing UC for the first time today and as soon as the browser opens it closes back again. I get the same:
Exception ignored in: <function Chrome.del at 0x000002C997BFC400> Traceback (most recent call last): File "G:\My Drive...\venv\Lib\site-packages\undetected_chromedriver__init.py", line 777, in del__ File "G:\My Drive...\venv\Lib\site-packages\undetected_chromedriver__init__.py", line 732, in quit OSError: [WinError 6] The handle is invalid
i use Python 3.9.13 works perfectly fine, try using that if you want
Thanks. I just swapped my interpreter to 3.9 and I do not get the error, but still my browser is closing almost immediately. I was having that issue with the original selenium webdriver and I had to change some options. But those are not working with UC. Any ideas?
hmm send the beginning of ur code to open browser and make sure your chrome is on latest and this is what i use
from selenium.webdriver.common.by import By # locate elements
from selenium.webdriver.chrome.options import Options
import undetected_chromedriver as uc
options = Options()
driver = uc.Chrome(options=options)
mine crashes with all 3.9 and 3.11 3.10.7, none worked. Same error
Exception ignored in: <function Chrome.__del__ at 0x0000017C5A90A200>
Traceback (most recent call last):
File "C:\Users\user\uc\undetected-chromedriver\undetected_chromedriver\__init__.py", line 777, in __del__
File "C:\Users\user\uc\undetected-chromedriver\undetected_chromedriver\__init__.py", line 732, in quit
OSError: [WinError 6] The handle is invalid```
hmm send the beginning of ur code to open browser and make sure your chrome is on latest and this is what i use
from selenium.webdriver.common.by import By # locate elements from selenium.webdriver.chrome.options import Options import undetected_chromedriver as uc options = Options() driver = uc.Chrome(options=options)
Thank you @sufianadnan I have the exact same code as you, still the browser opens and then closes on its own
import undetected_chromedriver as uc from selenium.webdriver.chrome.options import Options
options = Options() driver = uc.Chrome(options=options) driver.get("https://nowsecure.nl/")
I wonder if it has anything to do with lastest version of chromedriver not matching current chrome version https://chromedriver.storage.googleapis.com/LATEST_RELEASE
Fixed in #1031
Just tested again on 3.11 and still doesnt work. Same error. But when I change my interpreter to 3.09 it does work. any ideas? @ManiMozaffar
Just tested again on 3.11 and still doesnt work. Same error. But when I change my interpreter to 3.09 it does work. any ideas? @ManiMozaffar
Please use my repo code, perhaps. I'm running on python 3.11, and I had this issue, but using this repo I gave you I don't have any issue.
Just tested again on 3.11 and still doesnt work. Same error. But when I change my interpreter to 3.09 it does work. any ideas? @ManiMozaffar
Please use my repo code, perhaps. I'm running on python 3.11, and I had this issue, but using this repo I gave you I don't have any issue.
Thanks, where can I find your repo code? Sorry, I don't see any and I am fairly new to this. Trying to figure things out
Whats the solution to this issue . I am getting this issue now with undetected chromedriver
Same
Same to me (I am trying to access tiktok with this code) import undetected_chromedriver as uc
driver = uc.Chrome() driver.get( 'https://www.tiktok.com' )
I have made a solution but I don't know if it's good, but it does fix the issue for me. In the init.py around lines 780 - 790 there is a function:-
def __del__(self):
try:
self.service.process.kill()
except: # noqa
pass
self.quit()
My solution is that I have scoped self.quit()
inside except:
def __del__(self):
try:
self.service.process.kill()
except: # noqa
# pass
self.quit()
I looked into the self.quit()
and there I found the following:
def quit(self):
try:
self.service.process.kill()
logger.debug("webdriver process ended")
except (AttributeError, RuntimeError, OSError):
pass
.
.
.
Here you can see self.service.process.kill()
is again called inside try:
Maybe this is causing the problem as this kill()
function is being invoked two times now, once in __del__()
and again in quit()
.
Also, note my analysis is rookie and needs some insights from the developers here 😄.
Update
I have also found that commenting the time.sleep(0.1)
inside def quit(self):
also removes the error. I don't know why? But it does work🤷♂️
does anyone have a solution to the problem, the fix from muhammad did nothing for me unfortunately, I get the error in the del method at line 272. I use Python 3.11
Having the same issue using Python 3.11.4.
Browser is closing almost instantly.
Chrome is updated to last version.
UPDATE: I see it is exactly the previous comment fix.
Solved it with the fix described here:
_You can avoid this problem by modifying code in the undetectedchromedriver__init__.py.
Go to line 755 (it was not the line in my case) and wrap the time.sleep(0.1) with try-except block here is how the final code look like
try:
time.sleep(0.1)
except OSError:
pass
are you using driver.close() or driver.quit() try changing between them and see if that helps
Works for me on 3.11.2. I was originally using driver.quit() but driver.close() seems to avoid the issue.
are you using driver.close() or driver.quit() try changing between them and see if that helps
This solved my problem. I only used close() and works fine. Thanks Python version: 3.11.0
Nothing worked for me on a consistent basis, so I just suppressed the exception:
import undetected_chromedriver as uc
def suppress_exception_in_del(uc):
old_del = uc.Chrome.__del__
def new_del(self) -> None:
try:
old_del(self)
except:
pass
setattr(uc.Chrome, '__del__', new_del)
suppress_exception_in_del(uc)
You might want to be more specific in your except
clause.
Nothing worked for me on a consistent basis, so I just suppressed the exception:
import undetected_chromedriver as uc def suppress_exception_in_del(uc): old_del = uc.Chrome.__del__ def new_del(self) -> None: try: old_del(self) except: pass setattr(uc.Chrome, '__del__', new_del) suppress_exception_in_del(uc)
You might want to be more specific in your
except
clause.
works for me.thanks alot
Does anyone in the email chain actually have a working version of Undetected Chromedriver? I could never consistently get it to work.
What version of Selenium is it stable on?
On Mon, Jul 31, 2023 at 5:14 PM Meihb @.***> wrote:
Nothing worked for me on a consistent basis, so I just suppressed the exception:
import undetected_chromedriver as uc def suppress_exception_in_del(uc): old_del = uc.Chrome.del
def new_del(self) -> None: try: old_del(self) except: pass setattr(uc.Chrome, '__del__', new_del)
suppress_exception_in_del(uc)
You might want to be more specific in your except clause.
works for me.thanks alot
— Reply to this email directly, view it on GitHub https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/955#issuecomment-1659499803, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXUNOOSTKZKKFUTHDKLC6Z3XTBYAVANCNFSM6AAAAAATCNSE6I . You are receiving this because you commented.Message ID: @.*** com>
Does anyone in the email chain actually have a working version of Undetected Chromedriver? I could never consistently get it to work. What version of Selenium is it stable on?
I'm using selenium 4.9.1. If you patch uc
before actually using it, it should work, ... unless you're getting a crash somewhere else in uc.
I solved it! Just use
time.sleep(1)
under driver.close()
and it's gonna close just fine. The problem is that the object is destroyed while code is waiting.
I solved it! Just use
time.sleep(1)
underdriver.close()
and it's gonna close just fine. The problem is that the object is destroyed while code is waiting.
If you add driver.quit()
after that, it stops working. Also, it doesn't work with driver.quit()
alone. Finally, are we sure a delay of 1 second is always enough?
I still recommend my approach, which always works.
Is this patch available through the UC github? Where does one find it
On Tuesday, August 1, 2023, Massimiliano Tomassoli @.***> wrote:
Does anyone in the email chain actually have a working version of Undetected Chromedriver? I could never consistently get it to work. What version of Selenium is it stable on?
I'm using selenium 4.9.1. If you patch uc before actually using it, it should work, ... unless you're getting a crash somewhere else in uc.
— Reply to this email directly, view it on GitHub https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/955#issuecomment-1660459896, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXUNOOQ2F2PBVSNJOZ4LM7LXTEIBVANCNFSM6AAAAAATCNSE6I . You are receiving this because you commented.Message ID: @.*** om>
Is this patch available through the UC github? Where does one find it
See my post above.
import undetected_chromedriver as uc
def suppress_exception_in_del(uc): old_del = uc.Chrome.del
def new_del(self) -> None:
try:
old_del(self)
except:
pass
setattr(uc.Chrome, '__del__', new_del)
suppress_exception_in_del(uc)
thanks a lot for this answer. It help me. Good luck!
Eu fiz uma solução, mas não sei se é bom, mas resolvo o problema para mim. Não existe uma função init .py nas linhas 780 - 790: -
def __del__(self): try: self.service.process.kill() except: # noqa pass self.quit()
Minha é solução que eu olhei para
self.quit()
dentroexcept:
def __del__(self): try: self.service.process.kill() except: # noqa # pass self.quit()
Encontrei
self.quit()
o seguinte:def quit(self): try: self.service.process.kill() logger.debug("webdriver process ended") except (AttributeError, RuntimeError, OSError): pass . . .
Aqui você pode ver
self.service.process.kill()
que é chamado novamente dentro.try:
Talvez isso esteja causando o problema, pois estakill()
função está sendo invocada duas vezes agora, uma vez em__del__()
e novamente emquit()
.Além disso, observe que minha análise é novata e precisa de alguns insights dos desenvolvedores aqui 😄.
I did it here and it worked. Are there any updates to the module? Is it fixed yet?
I solved it! Just use
time.sleep(1)
underdriver.close()
and it's gonna close just fine. The problem is that the object is destroyed while code is waiting.
I tried adding time.sleep(1)
under driver.close()
and it really worked.😄
I solved it by:
uc.Chrome(version_main=120, driver_executable_path=d_path)
I had the same problem and solved it this way:
import undetected_chromedriver as uc_orig
# Make a new class from uc_orig.Chrome and redefine quit() function to suppress OSError
class Chrome(uc_orig.Chrome):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def quit(self):
try:
super().quit()
except OSError:
pass
if __name__ == "__main__":
driver = Chrome(headless=False, use_subprocess=False)
driver.get("https://nowsecure.nl")
driver.save_screenshot("nowsecure2.png")
changer comment self.quit()
its work
I solve using psutil
process = psutil.Process(driver.browser_pid)
process.terminate()
Hey all,
Does anyone here have Leon's contact info? ultrafunkamsterdamThe author undetected-chromedriver.
Thanks
On Mon, May 6, 2024 at 10:02 AM Tayyab Elahi @.***> wrote:
I have an interesting issue on my side. Looping on a bunch of links works fine in Jupyter Notebook doesn't crash but when I put my whole code in .py file and try to run in a clean manner by putting main lines of code in main function it crashes after getting 3 links. My chrome driver code is: def get_driver(): try: options = webdriver.ChromeOptions() driver = uc.Chrome(driver_executable_path="chromedriver.exe", options=options, version_main=120) driver.get("https://tonybet.com/nz/live/football") return driver except Exception as e: print("Error in get_driver: ", e)
I mentioned version_main after referring to this article. Using windows11, python 3.12
Can anybody help try some of above solution of overriding class functions but didn't work. I am not using driver.quit or close anywhere in code.
— Reply to this email directly, view it on GitHub https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/955#issuecomment-2096808182, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXUNOOQZI4O2UC3BJJJGI23ZA7OUFAVCNFSM6AAAAAATCNSE6KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJWHAYDQMJYGI . You are receiving this because you commented.Message ID: @.*** com>
Hello, the actual solution is as follows: In the file "init.py", there are two changes to the undetected-chromedriver library. First, in the "quit" function, you need to move "time.sleep(0.1)" inside the "try" block. Like this:
for _ in range(5):
try:
shutil.rmtree(self.user_data_dir, ignore_errors=False)
time.sleep(0.1)
except FileNotFoundError:
pass
except (RuntimeError, OSError, PermissionError) as e:
logger.debug(
"When removing the temp profile, a %s occured: %s\nretrying..."
% (e.__class__.__name__, e)
)
else:
logger.debug("successfully removed %s" % self.user_data_dir)
break
# time.sleep(0.1)
Next, in the "del" method, move "self.quit()" inside the "try".
def __del__(self):
try:
self.service.process.kill()
self.quit()
except: # noqa
pass
# self.quit()
Note: This works even on Python version 3.12.0.
Im getting this error when trying to run the following code:
import undetected_chromedriver as uc driver = uc.Chrome() driver.get('https://google.com')