Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request failed with status code: 401 #965

Open
JasonMo1 opened this issue Jul 8, 2023 · 1 comment
Open

Request failed with status code: 401 #965

JasonMo1 opened this issue Jul 8, 2023 · 1 comment

Comments

@JasonMo1
Copy link

JasonMo1 commented Jul 8, 2023

I have fill all of the values, I want to know what's wrong with these code.
OS: Windows 11
rustc: 1.70.0 (90c541806 2023-05-31)
git2: 0.17.2

My code:

fn push_repo() -> Result<(), git2::Error> {
    let repo = Repository::open("cache/repo")?; 

    let mut remote = repo.find_remote("origin")?;

    remote.connect_auth(Direction::Push, Some(create_callbacks()), None).unwrap();
    repo.remote_add_push("origin", "refs/heads/temp:refs/heads/temp").unwrap();
    let mut push_options = PushOptions::default();
    let callbacks = create_callbacks();
    push_options.remote_callbacks(callbacks);
    remote.push(&["refs/heads/temp:refs/heads/temp"], Some(&mut push_options)).unwrap();

    std::mem::drop(remote);

    Ok(())
}
fn create_callbacks<'a>() -> RemoteCallbacks<'a>{
    let mut callbacks = RemoteCallbacks::new();
    callbacks.credentials(|_url, username_from_url, _allowed_types| {
        // Use the username from the url or a default one
        let username = username_from_url.unwrap_or("git");
        Cred::ssh_key(
            username,
            Some(std::path::Path::new("ssh_key/pushzig_rsa.pub")),
            std::path::Path::new("ssh_key/pushzig_rsa"),
            None,
        )
    });
    callbacks
}

Error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { code: -1, klass: 34, message: "request failed with status code: 401" }', src\main.rs:261:74
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\zos-index-generator.exe new` (exit code: 101)
@eyolas
Copy link

eyolas commented Feb 14, 2024

Same error for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants