2
votes

Trying to run python fabric 2 in windows 10

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

Giving the below error

Traceback (most recent call last):
File "c:\users\rg\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None, File "c:\users\rg\programs\python\python38\lib\runpy.py", line 87, in run_code
exec(code, run_globals) File "C:\Users\rg\Programs\Python\Python38\Scripts\fab.exe_main
.py", line 7, in File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\program.py", line 384, in run
self.execute() File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\program.py", line 566, in execute
executor.execute(*self.tasks) File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\executor.py", line 129, in execute
result = call.task(*args, **call.kwargs) File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\tasks.py", line 127, in call
result = self.body(*args, **kwargs) File "C:\Users\rg\Documents\Solr\python_scripts\Solr\fabfiles\fabfile.py", line 10, in test
c.run("echo hello") File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\context.py", line 95, in run
return self._run(runner, command, **kwargs) File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\context.py", line 102, in _run
return runner.run(command, **kwargs) File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\runners.py", line 363, in run
return self._run_body(command, **kwargs) File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\runners.py", line 411, in _run_body self.start(command, self.opts["shell"], self.env) File "c:\users\rg\programs\python\python38\lib\site-packages\invoke\runners.py", line 1271, in start
self.process = Popen( File "c:\users\rg\programs\python\python38\lib\subprocess.py", line 858, in init
self._execute_child(args, executable, preexec_fn, close_fds, File "c:\users\rg\programs\python\python38\lib\subprocess.py", line 1311, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args, OSError: [WinError 87] The parameter is incorrect

1

1 Answers

0
votes

This is a sort-of-a-bug in fabric (as of 2.6.0), see the discussion here:
https://github.com/fabric/fabric/issues/2142

Apparently, it shows up with Python 3.8 or 3.9, but not with 3.6 or 3.7.

To get around it, you can use c.run("echo hello", replace_env=False).

This is OK for local calls, but can be problematic for remote calls, because it means that the remote session will see all environment variable values (some of which may be sensitive) of your local session.