"不能以管理员身份运行时无法为用户数据目录创建临时目录"错误

Mar*_*o S 2 python selenium selenium-chromedriver selenium-webdriver

当我以管理员身份运行它时,我只能运行我的python selenium代码.如果我正常运行它会出现以下错误:

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)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

    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")
Run Code Online (Sandbox Code Playgroud)

我正在使用python 3.6,Windows 10和selenium 3.5

小智 11

我遇到了同样的错误,之前描述的任何内容都没有帮助我。我这样解决了这个问题:

  1. echo %temp%在 Windows 的命令行中输入
  2. 它回来了C:\TEMP\2(为什么???)
  3. 所以我创建了这个文件夹,之后一切都开始工作了

  • 这对我有用。就我而言,%temp% 指向 C:\Users\<user>\AppData\Local\Temp\2。在我手动创建“2”文件夹后,一切正常。 (3认同)

Ada*_*unj 6

快速解决方案:

转到路径C:\Users\Administrator\AppData\Local\Temp,然后创建一个新文件夹。将此新文件夹重命名为2

这将创建%temp%丢失的文件夹。


Ani*_*l_M 5

根据我的经验,您可能会遇到下列情况之一.
1)您的磁盘已满,因此没有足够的可用磁盘速度.尝试清空回收站或检查过度生成的临时文件并清除它们.

2)或者您已使用管理员权限安装了软件包,因此您的脚本没有适当的权限来执行.

3)TMP环境变量可能需要修改.
右键单击计算机,然后单击属性 - >高级系统设置 - >环境变量 - >
"用户变量",并将TEMP和TMP变量值更改为"c:\ temp".