"cannot create temp dir for user data dir" error when not running as admin
Asked Answered
B

10

14

I'm just able to run my python selenium code when I run it as admin. If I run it normally I get following error:

C:\startup>Python C:/startup/startupWebDriverScript.py    
Traceback (most recent call last):
  File "C:/startup/startupWebDriverScript.py", line 26, in connectGuest
    driver = webdriver.Chrome(chrome_options=chromeOptions,executable_path="C:/Python36/Chrome Webdriver/chromedriver.exe")
  File "C:\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot create temp dir for user data dir 
  (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.15063 x86_64)

This is my code:

    chromeOptions = Options()
    chromeOptions.add_argument("--use-fake-ui-for-media-stream")
    chromeOptions.add_argument("--kiosk")
    chromeOptions.add_argument("--disable-notifications")
    chromeOptions.add_argument("--disable-infobars")
    driver = webdriver.Chrome(chrome_options=chromeOptions,executable_path="C:/Python36/Chrome Webdriver/chromedriver.exe")

I'm using python 3.6, Windows 10 and selenium 3.5

Bhayani answered 6/9, 2017 at 4:12 Comment(0)
S
16

I got the same error and nothing described before helped me. I fixed the problem such a way:

  1. Enter echo %temp% in Windows' command-line
  2. It returned C:\TEMP\2 (Why???)
  3. So I created this folder and after that everything started to work
Submultiple answered 6/10, 2019 at 11:47 Comment(2)
This worked for me. In my case the %temp% was pointing to C:\Users\<user>\AppData\Local\Temp\2. After I manually created the "2" folder everything worked fine.Unamuno
Worked for me as well. First time experiencing this, it happend when a transfered my code to a windows server machine and execute outside the main SO directory. I manually created the "2" folder in %temp%Mccue
D
14

Based upon my experience, It is possible you have one of following situations.

  1. Either your disk is getting full, thus don't have enough free disks-pace. Try emptying your recycle bin or check for excessively generated temp files and clear those.

  2. Or you have installed packages using admin privileges and hence your script doesn't have proper privileges to execute.

  3. TMP environment variable may need modifications.
    right click on computer and then click on properties -> advanced system settings -> environment variables ->
    "User variables for " and change the TEMP and TMP vars values to "c:\temp".

Defalcation answered 6/9, 2017 at 4:30 Comment(0)
F
6

Quick solution:

Go to the path C:\Users\Administrator\AppData\Local\Temp, and create a new folder. Rename this new folder to 2

This creates the %temp% folder that was missing.

Frontiersman answered 13/11, 2019 at 13:42 Comment(0)
B
0

After trying a lot of different approaches I decided to downgrade the Chrome web driver and it started to work out fine.

Bhayani answered 6/9, 2017 at 4:44 Comment(2)
Pretty much curious to know which log/effect triggered the idea of downgrading chromedriver?Lifeline
Actually I compared my setup with another similar and working setup and the only difference was the chrome driver version. Unfortunately I did not understand what exactly was the underlying issue.Bhayani
B
0

Ironically, the same error message can be see on when using on Windows 10 with ChromDriver 2.37 / Chrome 65. My test code was running from within Eclipse instance. To resolve, I had to start Eclipse As an Administrator and everything worked as it should.

Bullyboy answered 20/3, 2018 at 11:45 Comment(0)
S
0

I got the same error and I deleted all files in C:\Users\user\AppData\Local\Temp.

After that everything worked.

Szczecin answered 9/9, 2019 at 7:55 Comment(0)
M
0
  1. Move the Temp folder to C:\Windows\Temp\
  2. Update your Temp/TMP in System variables
  3. If you're using a batch file, run it as administrator
Mandolin answered 3/7, 2020 at 7:11 Comment(0)
C
0

The answers above helped a little, but all of them are only temporary solutions. Why echo %tmp% returns C:\Users\ADMINI~1\AppData\Local\Temp\2? It is because for each session Windows creates a separate temp directory.
It is needed to prevent do it by changing 2 keys in Group Policy:

  1. Search/open for 'Edit Group Policy'
  2. Find and enable next keys in the folder Administrative Templates > Windows Components > Remote Desktop Services > Remote Desktop Session Host > Temporary folders
  • Do not delete temp folders upon exit
  • Do not use temporary folders per session

    I suppose you can try to change appropriate registry keys instead (not tested):
  • SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\DeleteTempDirsOnExit
  • SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\PerSessionTempDir

Restart server.

After server is restarted echo %tmp% will always return C:\Users\ADMINI~1\AppData\Local\Temp and the issue will never return for Chrome driver (fixed 10 servers using this way).

The source is here: https://admx.help/?Category=Windows_10_2016&Policy=Microsoft.Policies.TerminalServer::TS_TEMP_PER_SESSION

Chino answered 8/10, 2021 at 8:19 Comment(0)
M
0

go to this dir: C:\Users
open your user name like: "m.rahimi" and then continue to this directory: \AppData\Local\Temp
create a new folder and name it: "2" everything got ok

Mcgruder answered 9/7, 2022 at 5:25 Comment(0)
E
-1

Run as Admin. It solved the problem for me.

Extraordinary answered 25/1, 2020 at 9:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.