Closed pnthai88 closed 1 year ago
@pnthai88 Not sure if the service argument works as intended. Can you try with the following shortly? Should be doing the same internally.
# ...
executable_driver_location = ChromeDriverManager().install()
driver = Chrome(profile, options=chrome_options,
executable_path=executable_driver_location, uc_driver=uc_driver)
return driver
# ...
collections.defaultdict
came from -_- no stack for that?I tried with include the executable path and the error same.
except Exception as e:
import traceback
traceback.print_exc()
print(f"An error occurred while configuring the WebDriver: {str(e)}")
Traceback (most recent call last):
File ".\ChromeManager.py", line 286, in configure_driver
driver = Chrome(profile, options=chrome_options, base_drivers=(webdriver.Chrome,), service=service, uc_driver=uc_driver)
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 43, in __new__
ChromeDriverManager(*args, **kwargs).install()
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 189, in install
if not os.path.exists(self.executable_path):
File "C:\ProgramData\Anaconda3\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
An error occurred while configuring the WebDriver: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
As i see the problem is at undetected_chromedriver plugin
import undetected_chromedriver as uc_webdriver
// your work is awesome!
I tried with include the executable path and the error same.
except Exception as e: import traceback traceback.print_exc() print(f"An error occurred while configuring the WebDriver: {str(e)}")
Traceback (most recent call last): File ".\ChromeManager.py", line 286, in configure_driver driver = Chrome(profile, options=chrome_options, base_drivers=(webdriver.Chrome,), service=service, uc_driver=uc_driver) File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 43, in __new__ ChromeDriverManager(*args, **kwargs).install() File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 189, in install if not os.path.exists(self.executable_path): File "C:\ProgramData\Anaconda3\lib\genericpath.py", line 19, in exists os.stat(path) TypeError: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict An error occurred while configuring the WebDriver: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
oh wait a minute, are you sure that Chrome
(File ".\ChromeManager.py", line 286, in configure_driver) refers to selenium_profiles.webdriver.Chrome
and not undetected_chromedriver.webdriver.Chrome
?
According to the stack, it seems to me like you're passing the profile
as path in undetected_chromedriver.webdriver.Chrome
.
profile=profile
as following?
from selenium_profiles.webdriver import Chrome
executable_driver_location = ChromeDriverManager().install()
driver = Chrome(profile, options=chrome_options,
executable_path=executable_driver_location, uc_driver=uc_driver)
// your work is awesome!
Thank you!
i print parameters
executable_driver_location = C:\Users\...\chrome\chromedriver_gggg.exe (it's valid)
profile = profiles.Android() =
defaultdict(<function return_profile.<locals>.<lambda> at 0x000002BA33AA9B88>, {
'options': {'gpu': False, 'window_size': {'x': 384, 'y': 700}},
'cdp': {
'touch': True,
'maxtouchpoints': 10,
'cores': 8,
'patch_version': True,
'emulation': {
'mobile': True,
'width': 384,
'height': 700,
'deviceScaleFactor': 4,
'screenOrientation': {'type': 'portraitPrimary', 'angle': 0}
},
'useragent': {
'platform': 'Linux aarch64',
'acceptLanguage': 'en-US',
'userAgent': 'Mozilla/5.0 (Linux; Android 11; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Mobile
Safari/537.36',
'userAgentMetadata': {
'brands': [
{'brand': 'Google Chrome', 'version': '105'},
{'brand': 'Not)A;Brand', 'version': '8'},
{'brand': 'Chromium', 'version': '105'}
],
'fullVersionList': [
{'brand': 'Google Chrome', 'version': '105.0.5195.136'},
{'brand': 'Not)A;Brand', 'version': '8.0.0.0'},
{'brand': 'Chromium', 'version': '105.0.5195.136'}
],
'fullVersion': '105.0.5195.136',
'platform': 'Android',
'platformVersion': '11.0.0',
'architecture': '',
'model': 'HD1913',
'mobile': True,
'bitness': '',
'wow64': False
}
}
}
})
Traceback (most recent call last):
File ".\ChromeManager.py", line 272, in configure_driver
driver = Chrome(profile, options=chrome_options, base_drivers=(webdriver.Chrome,), service=service, uc_driver=uc_driver, seleniumwire_options=False)
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 43, in __new__
ChromeDriverManager(*args, **kwargs).install()
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 189, in install
if not os.path.exists(self.executable_path):
File "C:\ProgramData\Anaconda3\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
An error occurred while configuring the WebDriver: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
i changed the import
#from selenium_stealth import stealth
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import selenium_profiles
print(f"selenium_profiles.__version__ == {selenium_profiles.__version__}")
from selenium_profiles.webdriver import Chrome
from selenium_profiles.profiles import profiles
if chrome_method == "normal":
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
elif chrome_method == "profile":
from seleniumwire import webdriver as seleniumwirewebdriver
chrome_options = seleniumwirewebdriver.ChromeOptions()
if chrome_method == "normal":
# the normal configuration work fine
elif chrome_method == "profile":
profile = None
if 'Windows' in user_agent:
profile = profiles.Windows() # or .Android .Windows
elif 'Android' in user_agent:
profile = profiles.Android()
service = Service(executable_path=executable_driver_location)
from seleniumwire import webdriver as seleniumwirewebdriver
driver = Chrome(profile, options=chrome_options, base_drivers=(seleniumwirewebdriver.Chrome,), service=service, uc_driver=uc_driver, seleniumwire_options=False)
but the problem still happen, very strange
Traceback (most recent call last):
File ".\ChromeManager.py", line 277, in configure_driver
driver = Chrome(profile, options=chrome_options, base_drivers=(seleniumwirewebdriver.Chrome,), service=service, uc_driver=uc_driver, seleniumwire_options=False)
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 43, in __new__
ChromeDriverManager(*args, **kwargs).install()
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 189, in install
if not os.path.exists(self.executable_path):
File "C:\ProgramData\Anaconda3\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
An error occurred while configuring the WebDriver: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
Saving all_data... from len of USER-LIST 71
Traceback (most recent call last):
File ".\ChromeManager.py", line 277, in configure_driver
driver = Chrome(profile, options=chrome_options, base_drivers=(seleniumwirewebdriver.Chrome,), service=service, uc_driver=uc_driver, seleniumwire_options=False)
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 43, in __new__
ChromeDriverManager(*args, **kwargs).install()
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 189, in install
if not os.path.exists(self.executable_path):
File "C:\ProgramData\Anaconda3\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
An error occurred while configuring the WebDriver: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
here is the simple code that cause same problem
from flask import Flask, request
from selenium_profiles.webdriver import Chrome
from selenium_profiles.profiles import profiles
from seleniumwire import webdriver
import time
app = Flask(__name__)
@app.route('/start', methods=['GET'])
def start():
profile = profiles.Android() # or .Android
options = webdriver.ChromeOptions()
driver = Chrome(profile, options=options, base_drivers=(webdriver.Chrome,),
uc_driver=True
)
# get url
url = request.args.get('url')
driver.get(url)
time.sleep(100)
return "hello"
if __name__ == '__main__':
app.run(debug=False)
[2023-07-07 17:45:08,594] ERROR in app: Exception on /start [GET]
Traceback (most recent call last):
File "C:\Users\thaip\AppData\Roaming\Python\Python37\site-packages\flask\app.py", line 2529, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\thaip\AppData\Roaming\Python\Python37\site-packages\flask\app.py", line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\thaip\AppData\Roaming\Python\Python37\site-packages\flask\app.py", line 1823, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\thaip\AppData\Roaming\Python\Python37\site-packages\flask\app.py", line 1799, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File ".\test.py", line 14, in start
uc_driver=True
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 43, in __new__
ChromeDriverManager(*args, **kwargs).install()
File "C:\ProgramData\Anaconda3\lib\site-packages\undetected_chromedriver\__init__.py", line 189, in
install
if not os.path.exists(self.executable_path):
File "C:\ProgramData\Anaconda3\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not collections.defaultdict
127.0.0.1 - - [07/Jul/2023 17:45:08] "GET /start?url=google.com HTTP/1.1" 500 -
Ah... the problem is ...
Successfully uninstalled undetected-chromedriver-2.1.1
the fix
Installing collected packages: undetected_chromedriver
Successfully installed undetected_chromedriver-3.5.0
Ah... the problem is ...
Successfully uninstalled undetected-chromedriver-2.1.1
the fix
Installing collected packages: undetected_chromedriver Successfully installed undetected_chromedriver-3.5.0
huh that's weird, no idea why this occurs tbh.
Note here: as you're importing from seleniumwire import webdriver
and then specifying base_drivers=(seleniumwirewebdriver.Chrome,)
, you're automatically using seleniumwire (internally equivalent to seleniumwire_options=True
)
closing this issue as it seems like a bug within undetected-chromedriver
Describe the bug When i start it with flask, do my jobs on it, close the browser, start a new one with custom parameters ig. (start with url, ... etc). Then start a new browser again it cause error
python-code
error-message
Environment (please complete the following information):