admin管理员组文章数量:1356824
I have a FastAPI server with a Slack chatbot that launches Selenium for automating certain tasks. However, I'm encountering an issue when initializing the ChromeDriver with the --user-data-dir
argument:
user_data_dir = tempfile.mkdtemp()
chrome_options.add_argument(f"--user-data-dir={user_data_dir}")
# Initializing the driver
driver = webdriver.Chrome(options=chrome_options)
When I run this, it fails with the following error:
seleniummon.exceptions.SessionNotCreatedException: 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
When I connect on ssh to the server it works without doing nothing.
I tried change the path:
chrome_options.add_argument("--user-data-dir=/home/ubuntu/mytmp/")
I tried static path
chrome_options.add_argument("--user-data-dir=/home/ubuntu/mytmp/")
And I have always the same behaviour.
I use AWS Lightsail with Ubuntu 22.04.5 LTS
I have a FastAPI server with a Slack chatbot that launches Selenium for automating certain tasks. However, I'm encountering an issue when initializing the ChromeDriver with the --user-data-dir
argument:
user_data_dir = tempfile.mkdtemp()
chrome_options.add_argument(f"--user-data-dir={user_data_dir}")
# Initializing the driver
driver = webdriver.Chrome(options=chrome_options)
When I run this, it fails with the following error:
seleniummon.exceptions.SessionNotCreatedException: 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
When I connect on ssh to the server it works without doing nothing.
I tried change the path:
chrome_options.add_argument("--user-data-dir=/home/ubuntu/mytmp/")
I tried static path
chrome_options.add_argument("--user-data-dir=/home/ubuntu/mytmp/")
And I have always the same behaviour.
I use AWS Lightsail with Ubuntu 22.04.5 LTS
Share Improve this question asked Mar 28 at 17:39 mioreymiorey 9568 silver badges20 bronze badges1 Answer
Reset to default 0The quick fix:
Use tmux new-session -d -s mysession
Et VOILA !
What I tried before that:
AppArmor tweaks – ChromeDriver (installed via Snap) might be restricted by AppArmor. I added these rules to
/var/lib/snapd/apparmor/profiles/snap.chromium.chromedriver
:allow /tmp/** rw, allow /run/user/** rw, allow /dev/shm/** rw,
Checked for zombie ChromeDriver processes and kill them with:
ps aux | grep chromedriver
Tried various Chrome options, including:
chrome_options.add_argument("--no-sandbox")
...and several others
Attempted to start a TTY during Python execution
The solution:
The tmux
session is triggered via SSH through my CI/CD pipeline to ensure a session remains continuously open on the server. This setup bypasses the restrictions related to directory creation and usage due to the environment settings. My API isn't executed within the tmux environment, but tmux keeps the session alive, allowing the process to run without interference.
本文标签:
版权声明:本文标题:python - SessionNotCreatedException when launching Selenium ChromeDriver with FastAPI Slack bot on AWS Lightsail - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744021550a2577297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论