【问题标题】:OSError: [WinError 87] The parameter is incorrectOSError: [WinError 87] 参数不正确
【发布时间】:2021-06-28 16:37:12
【问题描述】:

尝试在 Windows 10 中运行 python Fabric 2

from fabric import task,SerialGroup,Connection
import os

USERNAME = os.getenv('USERNAME')
my_hosts = ["hostname"]
c = Connection(host="rg@host.com",connect_kwargs={"password":"abcd"})
@task
def test(c):
    print(USERNAME)
    c.run("echo hello")

给出以下错误

回溯(最近一次通话最后一次):
文件“c:\users\rg\programs\python\python38\lib\runpy.py”,行 194,在_run_module_as_main
返回_run_code(代码,main_globals,无,文件“c:\users\rg\programs\python\python38\lib\runpy.py”,行 87,在 run_code
执行(代码,run_globals)文件 "C:\Users\rg\Programs\Python\Python38\Scripts\fab.exe_main
.py", 第 7 行,在文件中 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\program.py", 第 384 行,运行中
self.execute() 文件 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\program.py", 第 566 行,执行中
executor.execute(*self.tasks) 文件 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\executor.py", 第 129 行,在执行中
结果 = call.task(*args, **call.kwargs) 文件 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\tasks.py", 第 127 行,在 调用
结果 = self.body(*args, **kwargs) 文件 "C:\Users\rg\Documents\Solr\python_scripts\Solr\fabfiles\fabfile.py", 第 10 行,在测试中
c.run("echo hello") 文件 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\context.py", 第 95 行,运行中
返回 self._run(runner, command, **kwargs) 文件 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\context.py", 第 102 行,在 _run
返回 runner.run(command, **kwargs) 文件 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\runners.py", 第 363 行,运行中
返回 self._run_body(command, **kwargs) 文件 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\runners.py", 第 411 行,在 _run_body self.start(command, self.opts["shell"], self.env) 文件 "c:\users\rg\programs\python\python38\lib\site-packages\invoke\runners.py", 第 1271 行,开始
self.process = Popen( 文件 "c:\users\rg\programs\python\python38\lib\subprocess.py", 第 858 行,在 init
self._execute_child(args, 可执行文件, preexec_fn, close_fds, 文件 "c:\users\rg\programs\python\python38\lib\subprocess.py", 第 1311 行,在 _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args, OSError: [WinError 87] 参数错误

【问题讨论】:

    标签: python python-3.x fabric python-fabric-2


    【解决方案1】:

    这是 fabric 中的一种错误(从 2.6.0 开始), 在此处查看讨论:
    https://github.com/fabric/fabric/issues/2142

    显然,它出现在 Python 3.8 或 3.9 中,但没有出现在 3.6 或 3.7 中。

    要绕过它,您可以使用c.run("echo hello", replace_env=False)

    这对于本地调用是可以的,但对于远程调用可能会出现问题,因为这意味着远程会话将看到本地会话的所有环境变量值(其中一些可能是敏感的)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多