0

I'm running a drush command on a list of sites and a few sites are asking for ssh password to access to the server and run drush locally. I want to avoid this on the Python code. Actually, I've bypassed this by just hitting enter every time to ask for a password, but I want to do it programmatically.

I've tried with the try exception condition but since the site prompts for password, the try command will never fail because isn't failing. It is running the command perfectly fine, but since I run this in a loop, the code cannot bypass those sites that ask for password without hitting enter.

Example code:

getuids = os.popen('platform drush -p ' + i + ' -- status --format=json')
outputuids=getuids.read()
print(outputuids)

Input message that I'm trying to avoid:

xxx.xxxx@appserver.xxx..drush.in's password: << (enter to bypass it)

I'm also thinking about using asyncio, but I'm not sure how it's going to behave in this particular situation.

  • You should try using utilities which can let you press a key, using that you can try to mimic a key press when there is a password prompt, one such utility is : https://www.codegrepper.com/code-examples/python/simulate+key+press+python – JayantSeth May 17 '22 at 08:36
  • Use [`subprocess.run`](https://docs.python.org/3/library/subprocess.html#subprocess.run) – donkopotamus May 17 '22 at 08:37
  • I actually using subprocess, but popen. def run_command(command): p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) return iter(p.stdout.readline, b'') – user2965052 May 17 '22 at 08:46

0 Answers0