“cannot create temp dir for user data dir” error when not running as admin

梦想的初衷 提交于 2019-12-23 16:56:08

问题


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


回答1:


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".




回答2:


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



回答3:


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




回答4:


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.




回答5:


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

After that everything worked.




回答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.



来源:https://stackoverflow.com/questions/46066670/cannot-create-temp-dir-for-user-data-dir-error-when-not-running-as-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!