推送到 Git 返回错误代码 403 致命:HTTP 请求失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7438313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:51:37  来源:igfitidea点击:

Pushing to Git returning Error Code 403 fatal: HTTP request failed

gitgithubdvcs

提问by Mike

I was able to clone a copy of this repo over HTTPS authenticated. I've made some commits and want to push back out to the GitHub server. Using Cygwin on Windows 7 x64.

我能够通过 HTTPS 身份验证克隆此 repo 的副本。我已经提交了一些提交,并想推回 GitHub 服务器。在 Windows 7 x64 上使用 Cygwin。

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
error: The requested URL returned error: 403 while accessing https://MichaelDrog
[email protected]/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

Also set it up with verbose mode. I'm still pretty baffled.

还可以使用详细模式进行设置。我还是很困惑。

C:\cygwin\home\XPherior\Code\lunch_call>set GIT_CURL_VERBOSE=1

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL connection using AES256-SHA
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
< WWW-Authenticate: Basic realm="GitHub"
<
* Ignoring the response-body
* Expire cleared
* Connection #0 to host github.com left intact
* Issue another request to this URL: 'https://[email protected]/dereker
dmann/lunch_call.git/info/refs?service=git-receive-pack'
* Couldn't find host github.com in the _netrc file; using defaults
* Re-using existing connection! (#0) with host github.com
* Connected to github.com (207.97.227.239) port 443 (#0)
* 0x23cb740 is at send pipe head!
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="GitHub"
* The requested URL returned error: 401
* Closing connection #0
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL re-using session ID
* SSL connection using AES256-SHA
* old SSL session ID is stale, removing
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs HTTP/1.1
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

* The requested URL returned error: 403
* Expire cleared
* Closing connection #0
error: The requested URL returned error: 403 while accessing https://MichaelDrog
[email protected]/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

These are the versions of git and curl that I have:

这些是我拥有的 git 和 curl 版本:

C:\Users\XPherior>git --version
git version 1.7.4.msysgit.0

C:\Users\XPherior>curl --version
curl 7.21.7 (amd64-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp
smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate Largefile NTLM SSL SSPI libz

回答by Xiao

I just got the same problem and just figured out what's cause.

我刚刚遇到了同样的问题,只是想出了是什么原因。

Github seems only supports ssh way to read&write the repo, although https way also displayed 'Read&Write'.

Github 似乎只支持 ssh 方式来读写 repo,尽管 https 方式也显示了“读写”。

So you need to change your repo config on your PC to ssh way:

因此,您需要将 PC 上的 repo 配置更改为 ssh 方式:

  1. edit .git/configfile under your repo directory
  2. find url=entry under section [remote "origin"]
  3. change it from url=https://[email protected]/derekerdmann/lunch_call.gitto url=ssh://[email protected]/derekerdmann/lunch_call.git. that is, change all the texts before @symbol to ssh://git
  4. Save configfile and quit. now you could use git push origin masterto sync your repo on GitHub
  1. 编辑.git/configrepo 目录下的文件
  2. url=在部分下找到条目[remote "origin"]
  3. 将其从 更改url=https://[email protected]/derekerdmann/lunch_call.giturl=ssh://[email protected]/derekerdmann/lunch_call.git。也就是说,将@符号之前的所有文本更改为ssh://git
  4. 保存config文件并退出。现在你可以用来git push origin master在 GitHub 上同步你的 repo

回答by Thiago Macedo

To definitely be able to login using httpsprotocol, you should first set your authentication credentialto the git Remote URI:

为了绝对能够使用https协议登录,您应该首先将您的身份验证凭据设置为 git Remote URI

git remote set-url origin https://[email protected]/user/repo.git

Then you'll be asked for a password when trying to git push.

然后在尝试时会要求您输入密码git push

In fact, this is on the http authentication format. You could set a password too:

其实这是关于http认证格式的。您也可以设置密码:

https://youruser:[email protected]/user/repo.git

You should be aware that if you do this, your github password will be stored in plaintext in your .git directory, which is obviously undesirable.

您应该知道,如果您这样做,您的 github 密码将在您的 .git 目录中以明文形式存储,这显然是不可取的。

回答by fetsh

One small addition to Sean's answer.

肖恩回答的一小部分补充。

Instead of editing .git/configfile manually, you can use git remote set-urlcommand.

.git/config您可以使用git remote set-url命令代替手动编辑文件。

In your case it should be:

在你的情况下,它应该是:

git remote set-url origin ssh://[email protected]/derekerdmann/lunch_call.git

I find it easier and cleaner, than messing around with dot-files.

我发现它比乱用点文件更容易和更干净。

回答by Gal Bracha

Edit .git/configfile under your repo directory

编辑.git/configrepo 目录下的文件

Find url=entry under section [remote "origin"]

url=在部分下查找条目[remote "origin"]

Change it from url=https://github.com/rootux/ms-Dropdown.gitto https://[email protected]/rootux/ms-Dropdown.git

将其更改url=https://github.com/rootux/ms-Dropdown.githttps://[email protected]/rootux/ms-Dropdown.git

where USERNAMEis your github user name

USERNAME你的github用户名在哪里

回答by BMB

The other answers that suggest switching to SSH sort of miss the point. HTTPS is supported, but you must log in with you GITHUB password, not your SSH passphrase (which was what was giving me the same exact error).

建议切换到 SSH 的其他答案有点没有抓住重点。支持 HTTPS,但您必须使用您的 GITHUB 密码登录,而不是您的 SSH 密码(这给了我同样的错误)。

I was having the same problem, but making sure to use my actual GitHub password at the terminal password prompt fixed the solution with no alteration to the config, or resorting to SSH.

我遇到了同样的问题,但确保在终端密码提示下使用我的实际 GitHub 密码修复了解决方案,而无需更改配置或诉诸 SSH。

The reason it is important to note this, is many public institutions (such as my school) will block SSH, but allow HTTPS (which is the only reason I started cloning over HTTPS in the first place).

重要的是要注意这一点,因为许多公共机构(例如我的学校)会阻止 SSH,但允许 HTTPS(这是我首先开始通过 HTTPS 进行克隆的唯一原因)。

Hope that helps anyone else having the same issue...

希望能帮助遇到同样问题的其他人...

回答by zeeawan

Same error and resolution on Mac OS X.

Mac OS X上的错误和解决方法相同

Everything was working fine till I created a new account on GitHuband tried to push

一切正常,直到我在 GitHub 上创建了一个新帐户并尝试推送

$ git push -u origin master

And got the error:

并得到错误:

remote: Permission to NEWUSER/NEWREPO.git denied to OLDUSER. fatal: unable to access ‘https://github.com/NEWUSER/NEWREPO.git/': The requested URL returned error: 403

远程:对 NEWUSER/NEWREPO.git 的权限被拒绝给 OLDUSER。致命:无法访问“ https://github.com/NEWUSER/NEWREPO.git/”:请求的 URL 返回错误:403

It should have fixed by setting the user.name either for global or current repo

它应该通过为全局或当前存储库设置 user.name 来修复

$ git config –-global user.name NEWUSER
$ git config user.name NEWUSER

But it didn't.

但它没有。

I got it fixed by deleting the OLDUSER associated with GitHub from Keychain Access appunder Passwords section. Then the push command went successful.

我通过从密码部分下的钥匙串访问应用程序中删除与 GitHub 关联的 OLDUSER 来修复它。然后推送命令成功。

$ git push -u origin master

reference

参考

回答by Andrew Gans

If you are using windows, sometimes this may happen because Windows stores credentials for outer repo (in our case github) in its own storage. And credentials that saved there can be different from those you need right now.

如果您使用的是 Windows,有时可能会发生这种情况,因为 Windows 将外部存储库(在我们的示例中为 github)的凭据存储在其自己的存储中。保存在那里的凭据可能与您现在需要的凭据不同。

enter image description here

在此处输入图片说明

So to avoid this problem, just find github in this storage and delete saved credentials. After this, while pushing git will request your credentials and will allow you to push.

所以为了避免这个问题,只需在这个存储中找到github并删除保存的凭据。在此之后,在推送时 git 将请求您的凭据并允许您推送。

回答by stevensagaar

This works for me -:

这对我有用-:

git remote set-url origin https://[email protected]/user/repo.git

Hope it helps

希望能帮助到你

回答by nisah

I think @deepwaters got the answer correct for older versions. The HTTPS URL needs to have the username. I had git 1.7.0.4 and git push origin masterwouldn't even ask for a password till I added it.

我认为@deepwaters 为旧版本提供了正确的答案。HTTPS URL 需要具有用户名。我有 git 1.7.0.4 并且git push origin master在我添加它之前甚至不会要求输入密码。

回答by gsf

Upgrade your git. GitHub has answered this question at https://help.github.com/articles/error-the-requested-url-returned-error-403.

升级你的 git。GitHub 已在https://help.github.com/articles/error-the-requested-url-returned-error-403回答了这个问题。