When I try to use Selenium, it gives an error in the first lines of the code
code:
driverLocation = "/usr/bin/chromedriver"
binaryLocation = "/usr/bin/google-chrome-stable"
chrome_options = Options()
dir = r"/home/ubuntu/.config/google-chrome/Default"
chrome_options.add_argument(f"--user-data-dir={dir}")
chrome_options.binary_location = binaryLocation
chrome_options.add_argument('--headless')
driver = UC.Chrome(executable_path=driverLocation, options=chrome_options)
error:
> Traceback (most recent call last):
File "main.py", line 34, in <module>
driver = UC.Chrome(executable_path=driverLocation, options=chrome_options)
File "/home/ubuntu/.local/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 233, in __init__
patcher.auto()
File "/home/ubuntu/.local/lib/python3.8/site-packages/undetected_chromedriver/patcher.py", line 130, in auto
self.unzip_package(self.fetch_package())
File "/home/ubuntu/.local/lib/python3.8/site-packages/undetected_chromedriver/patcher.py", line 166, in fetch_package
return urlretrieve(u)[0]
File "/usr/lib/python3.8/urllib/request.py", line 247, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/usr/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
And when I use Selenium web driver, it doesn't give this error (it only happens when I use undetected-chromedriver)
I run this code on Ubuntu 20.04 server with Chrome 103
And some of my servers do not give this error
And I set up all the servers in the same way