When trying to run a simple python script with selenium i get the error: session not created: probably user data directory is al

i am currently trying to run a python script that navigate on the web with selenium and get the html of

i am currently trying to run a python script that navigate on the web with selenium and get the html of the product page on a web site and then do scraping to collect info. The info are stored in a database mariadb. I am on a Rasberry pi 5 on Ubuntu, the version of Chromium is Chromium 134.0.6998.88 snap and the version of the chromedriver is ChromeDriver 134.0.6998.88 (7e3d5c978c6d3a6eda25692cfac7f893a2b20dd0-refs/branch-heads/6998@{#1898}). As the title said i can't run the script without getting the error:

   Message: session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
    Stacktrace:
    #0 0xaaaadab81694 <unknown>
    #1 0xaaaada6b58a4 <unknown>
    #2 0xaaaada6e89c8 <unknown>
    #3 0xaaaada6e51a4 <unknown>
    #4 0xaaaada72a0b8 <unknown>
    #5 0xaaaada729944 <unknown>
    #6 0xaaaada6f0b84 <unknown>
    #7 0xaaaadab4fd28 <unknown>
    #8 0xaaaadab531d8 <unknown>
    #9 0xaaaadab3f5e4 <unknown>
    #10 0xaaaadab53854 <unknown>
    #11 0xaaaadab276d0 <unknown>
    #12 0xaaaadab70980 <unknown>
    #13 0xaaaadab70b50 <unknown>
    #14 0xaaaadab8048c <unknown>
    #15 0xffffa7fad5c4 <unknown>
    #16 0xffffa8015ed8 <unknown>
    
    Traceback (most recent call last):
      File "/home/realtalker/data_workers/scraping_best/get_info_best.py", line 402, in <module>
        driver.quit()
        ^^^^^^
    NameError: name 'driver' is not defined. Did you mean: 'webdriver'?

My chrome options are:

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--headless=new')
options.add_argument('--disable-gpu')
options.add_argument('--disable-extensions')
options.add_argument('--remote-debugging-port=9222') # Specify a port
options.add_argument('--disable-setuid-sandbox')

options.add_argument("--incognito")
options.add_argument("--disable-application-cache")
options.add_argument("--enable-do-not-track")
options.add_argument("--disable-popup-blocking")

options.binary_location = '/snap/bin/chromium'

service = Service('/usr/bin/chromedriver')

I saw in a github report that maybe there is a problem when running as root, i checked and i am not running as root, i tried to run the chromedriver and:

(.venv) realtalker@ubuntu:~/data_workers/scraping_best$ chromedriver
Starting ChromeDriver 133.0.6943.141 (2a5d6da0d6165d7b107502095a937fe7704fcef6-refs/branch-heads/6943@{#1912}) on port 0
Only local connections are allowed.
Please see  for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully on port 42027.

so i checked with ps -aux | grep chromedriver and i got:

realtal+  167950  4.1  0.1 33614684 13824 pts/2  Sl+  16:46   0:00 /snap/chromium/3053/usr/lib/chromium-browser/chromedriver
realtal+  168021  0.0  0.0   6676  1920 pts/1    S+   16:46   0:00 grep --color=auto chromedriver

then i tried to run the same command to check with chromium before i could get the error and:

realtal+  168029 14.4  0.1 33622940 14720 pts/2  Sl+  16:48   0:00 /snap/chromium/3053/usr/lib/chromium-browser/chromedriver --port=60075
realtal+  168103  0.0  0.0   6676  1920 pts/1    S+   16:48   0:00 grep --color=auto chromium

IMPORTANT: I am on a raspberry pi 5 that runs ubuntu server (Linux ubuntu 6.8.0-1018-raspi #20-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan 17 12:35:36 UTC 2025 aarch64 aarch64 aarch64 GNU/Linux)

I even tried to launch chromium from the command line:

realtalker@ubuntu:~/data_workers/scraping_best$ /snap/bin/chromium --headless --disable-gpu --remote-debugging-port=9222

[171851:171946:0319/084459.213021:ERROR:object_proxy(576)] Failed to call method: .freedesktop.DBus.ListActivatableNames: object_path= //freedesktop/DBus: .freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.23" (uid=1000 pid=171851 comm="/snap/chromium/3053/usr/lib/chromium-browser/chrom" label="snap.chromium.chromium (enforce)") interface=".freedesktop.DBus" member="ListActivatableNames" error name="(unset)" requested_reply="0" destination=".freedesktop.DBus" (bus)
X11 connection rejected because of wrong authentication.
[171959:171959:0319/084459.253731:ERROR:angle_platform_impl(44)] DisplayVkXcb.cpp:58 (initialize): xcb_connect() failed, error 1
ERR: DisplayVkXcb.cpp:58 (initialize): xcb_connect() failed, error 1
[171959:171959:0319/084459.255771:ERROR:angle_platform_impl(44)] Display.cpp:1085 (initialize): ANGLE Display::initialize error 12289: Not initialized.
ERR: Display.cpp:1085 (initialize): ANGLE Display::initialize error 12289: Not initialized.
[171851:171946:0319/084459.257144:ERROR:object_proxy(576)] Failed to call method: .freedesktop.DBus.ListActivatableNames: object_path= //freedesktop/DBus: .freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.25" (uid=1000 pid=171851 comm="/snap/chromium/3053/usr/lib/chromium-browser/chrom" label="snap.chromium.chromium (enforce)") interface=".freedesktop.DBus" member="ListActivatableNames" error name="(unset)" requested_reply="0" destination=".freedesktop.DBus" (bus)
[171959:171959:0319/084459.257431:ERROR:gl_display(495)] EGL Driver message (Critical) eglInitialize: Not initialized.
[171959:171959:0319/084459.259674:ERROR:gl_display(767)] eglInitialize SwANGLE failed with error EGL_NOT_INITIALIZED
[171959:171959:0319/084459.261020:ERROR:gl_display(802)] Initialization of all EGL display types failed.
[171959:171959:0319/084459.261338:ERROR:gl_ozone_egl(26)] GLDisplayEGL::Initialize failed.
X11 connection rejected because of wrong authentication.

DevTools listening on ws://127.0.0.1:9222/devtools/browser/0af8722f-4fb6-4558-893d-01bc49c978e6
[171959:171959:0319/084459.291606:ERROR:angle_platform_impl(44)] DisplayVkXcb.cpp:58 (initialize): xcb_connect() failed, error 1
ERR: DisplayVkXcb.cpp:58 (initialize): xcb_connect() failed, error 1
[171959:171959:0319/084459.291969:ERROR:angle_platform_impl(44)] Display.cpp:1085 (initialize): ANGLE Display::initialize error 12289: Not initialized.
ERR: Display.cpp:1085 (initialize): ANGLE Display::initialize error 12289: Not initialized.
[171959:171959:0319/084459.292095:ERROR:gl_display(495)] EGL Driver message (Critical) eglInitialize: Not initialized.
[171959:171959:0319/084459.292220:ERROR:gl_display(767)] eglInitialize SwANGLE failed with error EGL_NOT_INITIALIZED
[171959:171959:0319/084459.292324:ERROR:gl_display(802)] Initialization of all EGL display types failed.
[171959:171959:0319/084459.292424:ERROR:gl_ozone_egl(26)] GLDisplayEGL::Initialize failed.
[171959:171959:0319/084459.296504:ERROR:viz_main_impl(185)] Exiting GPU process due to errors during initialization
[171851:172048:0319/084459.485882:ERROR:object_proxy(576)] Failed to call method: .freedesktop.DBus.Properties.Get: object_path= //freedesktop/UPower: .freedesktop.DBus.Error.ServiceUnknown: The name .freedesktop.UPower was not provided by any .service files
[171851:172048:0319/084459.486640:ERROR:object_proxy(576)] Failed to call method: .freedesktop.UPower.GetDisplayDevice: object_path= //freedesktop/UPower: .freedesktop.DBus.Error.ServiceUnknown: The name .freedesktop.UPower was not provided by any .service files
[171851:172048:0319/084459.487404:ERROR:object_proxy(576)] Failed to call method: .freedesktop.UPower.EnumerateDevices: object_path= //freedesktop/UPower: .freedesktop.DBus.Error.ServiceUnknown: The name .freedesktop.UPower was not provided by any .service files
[171851:171851:0319/084459.489651:ERROR:object_proxy(576)] Failed to call method: .freedesktop.DBus.ListActivatableNames: object_path= //freedesktop/DBus: .freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.24" (uid=1000 pid=171851 comm="/snap/chromium/3053/usr/lib/chromium-browser/chrom" label="snap.chromium.chromium (enforce)") interface=".freedesktop.DBus" member="ListActivatableNames" error name="(unset)" requested_reply="0" destination=".freedesktop.DBus" (bus)
X11 connection rejected because of wrong authentication.
[172043:172043:0319/084459.527283:ERROR:angle_platform_impl(44)] DisplayVkXcb.cpp:58 (initialize): xcb_connect() failed, error 1
ERR: DisplayVkXcb.cpp:58 (initialize): xcb_connect() failed, error 1
[172043:172043:0319/084459.528824:ERROR:angle_platform_impl(44)] Display.cpp:1085 (initialize): ANGLE Display::initialize error 12289: Not initialized.
ERR: Display.cpp:1085 (initialize): ANGLE Display::initialize error 12289: Not initialized.
[172043:172043:0319/084459.532064:ERROR:gl_display(495)] EGL Driver message (Critical) eglInitialize: Not initialized.
[172043:172043:0319/084459.532936:ERROR:gl_display(767)] eglInitialize SwANGLE failed with error EGL_NOT_INITIALIZED
[172043:172043:0319/084459.533325:ERROR:gl_display(802)] Initialization of all EGL display types failed.
[172043:172043:0319/084459.533495:ERROR:gl_ozone_egl(26)] GLDisplayEGL::Initialize failed.
X11 connection rejected because of wrong authentication.
[172043:172043:0319/084459.566273:ERROR:angle_platform_impl(44)] DisplayVkXcb.cpp:58 (initialize): xcb_connect() failed, error 1
ERR: DisplayVkXcb.cpp:58 (initialize): xcb_connect() failed, error 1
[172043:172043:0319/084459.566815:ERROR:angle_platform_impl(44)] Display.cpp:1085 (initialize): ANGLE Display::initialize error 12289: Not initialized.
ERR: Display.cpp:1085 (initialize): ANGLE Display::initialize error 12289: Not initialized.
[172043:172043:0319/084459.567212:ERROR:gl_display(495)] EGL Driver message (Critical) eglInitialize: Not initialized.
[172043:172043:0319/084459.567754:ERROR:gl_display(767)] eglInitialize SwANGLE failed with error EGL_NOT_INITIALIZED
[172043:172043:0319/084459.568070:ERROR:gl_display(802)] Initialization of all EGL display types failed.
[172043:172043:0319/084459.568351:ERROR:gl_ozone_egl(26)] GLDisplayEGL::Initialize failed.
[172043:172043:0319/084459.578120:ERROR:viz_main_impl(185)] Exiting GPU process due to errors during initialization

The code that now i try to run is a simple one (ignore the import library because i copied from an other code):

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdrivermon.by import By
from selenium.webdrivermon.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdrivermon.keys import Keys
from seleniummon.exceptions import TimeoutException, ElementClickInterceptedException
import time
from datetime import date, datetime, timedelta
from bs4 import BeautifulSoup as bs4
import mysql.connector
import re


options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--headless=new')
options.add_argument('--disable-gpu')
options.add_argument('--disable-extensions')
options.add_argument('--remote-debugging-port=9222')  # Specify a port
options.add_argument('--disable-setuid-sandbox')

options.add_argument("--incognito")
options.add_argument("--disable-application-cache")
options.add_argument("--enable-do-not-track")
options.add_argument("--disable-popup-blocking")

options.binary_location = '/snap/bin/chromium'

service = Service('/usr/bin/chromedriver')

driver = webdriver.Chrome(service=service, options=options)

driver.get(";)

time.sleep(2)

title = driver.title
print("Title of the page:", title)

driver.quit()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744400357a4572354.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信