How to set the credentials in pygit2.clone_repository?

3.2k views Asked by At

When I clone a repo from github by pygit2, it returns: 'OSError: Failed to send request: A security error occurred'
The code is simple,

import pygit2

username = 'MyGitHubUsername'
password = 'MyGitHubPassword'
cred = pygit2.UserPass(username, password)
repo = pygit2.clone_repository('https://github.com/libgit2/libgit2', 'C:/test', bare=False, credentials=cred)

But it doesn't work, is this right?

1

There are 1 answers

0
Carlos Martín Nieto On BEST ANSWER

Does using the exact same username and password work with git? If you have two-factor authentication activated, your normal password won't work. You have to create a new token and use that as your password.

Also make sure that the error is due to the credentials. "security error" could just as well mean that the HTTPS certificate of github.com is not recognised by your computer (looks like you might be using WinHTTP).