3

I am using gitpython library to execute git commands from a python script.

When I execute git pull, it fails giving the following error: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

However, git pull runs successfully when I run it directly from shell. Added to this, other git commands such as git status, git log, are all working fine. ONLY git pull/push gives the above error.

This is the python script:

import os
import git
g = git.cmd.Git(local_repo_path)
os.chdir(local_repo_path)
g.checkout('master') // this works fine
msg = g.pull()
print msg // gives an error mentioned below

Output is:

git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git pull
  stderr: 'Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.

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

What could be the possible reason ?

Shayan Anwar
  • 149
  • 2
  • 10

1 Answers1

0

The problem here was the user authentication. Shell uses global git username to authenticate, so it works. However, the python script git commands use the repo username which is not same as the expected git username. So, setting the username explicitly for python script will work. Inside your local git repo,

Run: git config -e

Add in this:

[user]
name = yourname
email = youremail

This will make sure your python script uses this info.

Shayan Anwar
  • 149
  • 2
  • 10