0

I am new to python and I want to git clone SSH key with passphrase. By referring this https://stackoverflow.com/a/45219868/12095967 , I tried it as:

from subprocess import Popen, PIPE

password = 'Password@'
proc = Popen(['git', 'clone', 'git@gitlab.com:gitlab.com/julie/board.git'], stdin=PIPE)
proc.communicate(password)

And this is the output it gives:

Traceback (most recent call last):
  File "C:\Users\dell\eclipse-workspace\GitTrial\Git\__init__.py", line 123, in <module>
    proc.communicate(password)
  File "C:\Users\dell\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1009, in communicate
    self._stdin_write(input)
  File "C:\Users\dell\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 958, in _stdin_write
    self.stdin.write(input)
TypeError: a bytes-like object is required, not 'str'
Cloning into 'board'...
Permission denied, please try again.
Permission denied, please try again.
git@gitlab.com: Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I am using windows 10. Can someone help me out with this?

makozaki
  • 3,772
  • 4
  • 23
  • 47
Blessy Julie
  • 899
  • 3
  • 8
  • 19

1 Answers1

1

Logs indicate:

...
    proc.communicate(password)
...
TypeError: a bytes-like object is required, not 'str'

Password should be bytes instead of string:

password = b'Password@'
makozaki
  • 3,772
  • 4
  • 23
  • 47
  • And abt Permission denied (publickey,password). fatal: Could not read from remote repository. – Blessy Julie Mar 27 '20 at 11:43
  • What happens when you go to console and do it manually? `git clone git@gitlab.com:gitlab.com/julie/board.git` – makozaki Mar 27 '20 at 12:09
  • Shouldn't this be `git@gitlab.com:julie/board.git`? SSH url to your project seems to be wrong. – makozaki Mar 27 '20 at 12:16
  • I think it is right as I m able to clone using GitBash , but unable to using python . Can u help me where I can mention the location to where I want to clone ? – Blessy Julie Mar 27 '20 at 13:16
  • So what is the status does the script work or it still produces `Permission denied` error? – makozaki Mar 27 '20 at 13:31
  • Can you pipe the password to your gitbash command? I mean something like this `echo Password@ | git clone git@gitlab.com:julie/board.git` – makozaki Mar 27 '20 at 13:52
  • Is it necessary for you to use ssh with passphrase? – makozaki Mar 31 '20 at 09:51