Python &引用;无法为用户数据目录创建临时目录";不以管理员身份运行时出错

Python &引用;无法为用户数据目录创建临时目录";不以管理员身份运行时出错,python,selenium,selenium-webdriver,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Selenium Chromedriver,当我以管理员的身份运行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.C

当我以管理员的身份运行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)
这是我的代码:

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

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

根据我的经验,可能存在以下情况之一

  • 或者磁盘已满,因此没有足够的可用磁盘。尝试清空回收站或检查生成的临时文件是否过多,然后清除这些临时文件

  • 或者您使用管理员权限安装了包,因此您的脚本没有适当的权限执行

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


  • 在尝试了许多不同的方法后,我决定降低Chrome web驱动程序的等级,结果很好。

    讽刺的是,在Windows 10上使用Chrome driver 2.37/Chrome 65时,同样的错误信息也会出现。我的测试代码是从Eclipse实例中运行的。要解决这个问题,我必须以管理员的身份启动Eclipse,一切都正常运行。

    我遇到了同样的错误,我删除了
    C:\Users\user\AppData\Local\Temp
    中的所有文件


    在那之后,一切都正常了。

    我也犯了同样的错误,之前所描述的一切对我都没有帮助。 我这样解决了这个问题:

  • 在Windows的命令行中输入
    echo%temp%
  • 它返回
    C:\TEMP\2
    (为什么?)
  • 所以我创建了这个文件夹,然后一切都开始工作了
  • 快速解决方案:

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


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

    以管理员身份运行。它为我解决了问题

  • 将临时文件夹移到C:\Windows\Temp\
  • 更新系统变量中的Temp/TMP
  • 如果您使用的是批处理文件,请以管理员身份运行它

  • 非常想知道是哪个日志/效果触发了降级
    chromedriver
    的想法?实际上,我将我的设置与另一个类似的工作设置进行了比较,唯一的区别是chrome驱动程序版本。不幸的是,我不明白到底什么是潜在的问题。这对我很有效。在我的例子中,%temp%指向C:\Users\\AppData\Local\temp\2。在我手动创建了“2”文件夹之后,一切都很好。对我来说也很好。第一次遇到这种情况时,它发生在a将我的代码传输到windows server计算机并在主SO目录外执行时。我在%temp%中手动创建了“2”文件夹