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

819

我能够通过HTTPS认证克隆该存储库的一个副本。我已经提交了一些更改并希望将它们推送回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
alis@github.com/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

同时设置为详细模式。我仍然感到相当困惑。

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://MichaelDrogalis@github.com/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
alis@github.com/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

以下是我所拥有的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

4
看一下这条评论,应该发布为答案。我让它在1.7.1版本中工作了,也遇到了缺少用户/密码提示的问题。感谢 https://dev59.com/K2s05IYBdhLWcg3wG-VR#9575906 提供的帮助... - sjas
3
检查用户对仓库是否具有读写权限。 - Céline Aussourd
42
将来展示示例HTTP头时,请勿粘贴“Authorization: Basic <stuff>”。这很容易被Base64解码并获取您的密码。@Mike:如果您自发布此问题以来没有更改GitHub密码,建议您这样做。 - FlipMcF
6
谢谢,我不知道这个事情。已经更改了密码。 - Mike
8
@Mike 没问题。现在我可以毫不掩饰地宣传一下我写的博客:http://goo.gl/bpae94 - FlipMcF
显示剩余9条评论
75个回答

1
我遇到了同样的问题。我的情况是:在github上创建repo之前,我已经在本地初始化了git repo,然后我尝试添加远程分支。通过改变操作顺序来解决了我的问题:先在github网站上创建repo,然后在本地初始化它。但对于像我一样喜欢全程使用命令行的人来说,情况并非如此。

1
我所做的是将 http 改为 ssh:
git remote rm origin
git remote add origin git@github.com:username/repoName.git

然后用git remote -v命令检查它


1
在我的情况下,这个错误是由于我在仓库中没有权限造成的。

1
我现在遇到了这个问题,结果发现我的服务器 /etc/resolver.conf 文件有一个错误的 IP 地址。这可能会对其他人有所帮助。

1
将私有的 git 仓库变为公共的。

我完全不建议这样做,保持私密性,使用访问令牌并为该令牌授予权限! 你可以在这里找到它: https://github.com/settings/tokens - roudlek

1

我解决了这个"Permission denied"的问题,只需要做以下几步:

1.) 将git升级到最新版本。

2.) 通过在git-bash中输入命令 "git remote set-url origin https://username@github.com/username/repo_name.git",将远程URL更改为格式为 "https://username@github.com/username/repo_name.git"

之前,我使用的是2.28版本,所以没有出现登录界面提示。通过更改URL,我可以使用git-hub凭据登录并将更改推送到仓库。


确实,旧机器上过时的 Git 命令行界面是问题的原因,尝试在我新笔记本电脑上使用最新版本的相同命令解决了它。 - RAM237

1

唯一帮助我的是另一个问题的答案:

Git 的著名错误:“ERROR:Permission to .git denied to user”

简而言之,如果你和我一样使用 Windows,搜索“凭据管理器”并打开它。在那里,你可以找到你的 Git 凭据。更改用户名(你必须已经改成其他内容了)。

你也可以在“控制面板”-“用户账户”-“凭据管理器”下找到它。


1
只是想再补充一个我遇到的情况,我的公司要求单点登录,因此当我创建/更新我的新发布令牌时,我忘记授权它,并开始从github收到这些403响应。

enter image description here

enter image description here

我怀疑这种干扰可能很常见


0
要解决推送时出现的403错误,您需要进入.git目录配置文件并更改给定行:
precomposeunicode = true
[remote "origin"]
http://git@github.com:abc/xyz.git

将此行更改为以下内容
precomposeunicode = true
[remote "origin"]
ssh://git@github.com/abc/xyz.git

这解决了我的问题。


0

还有一个可能是在github.com上进行电子邮件验证

只需登录github.com并检查是否有确认您的电子邮件地址的消息。如有必要,请进行确认。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接