提交到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个回答

16

这肯定是答案的一半。另一半就在我们这里。 - Mike

15

403代码表示“禁止访问”。服务器看到了您的请求并拒绝了它。您是否有权限向该存储库推送?


1
我和一个朋友遇到了同样的问题。这个仓库是我的,他无法推送。我们该怎么解决? - gibson
如何获取权限 - Bawantha
将您的朋友添加到仓库的访问列表中。https://help.github.jp/enterprise/2.11/user/articles/inviting-collaborators-to-a-personal-repository/ - Uday Chauhan

12

我解决了这个问题。我是通过HTTPS克隆的。设置我的公共SSH密钥,通过SSH克隆和推送修复了它。


嗯...但是如果由于公司防火墙等原因,你只能使用https怎么办呢?根据Github博客的说法,添加https访问就是为了这个目的。 - filofel
1
我真的不知道。现在我总是通过SSH克隆。 - Mike
仅供记录(我注意到了时间戳),关于filofel的评论:请查看我上面列出的答案。我在学校也遇到了你提到的同样限制,并发现我向终端提示输入了错误的密码/密码短语。希望它能帮助其他遇到相同问题的人。 - BMB

11

这是一个临时解决方法:

git push -u https://username:password@github.com/username/repo_name.git master


10

实际上,我有一个非常简单的解决方法。在克隆存储库后,我的做法是以不同的方式编辑git配置文件。在默认的config文件中,你需要编辑远程origin的URL,它应该看起来像下面这样。

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://*username*@github.com/*username*/*repository*.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

^ 这个(或其以下任何变体之一) - Austin France
在 github.com 前面加上用户名,问题就解决了。 - Shane
欢迎您,@ÅdəəlÅhmåd。如果您能给这个答案点赞支持一下,那么更多的人也能受益于此。 - Akah

10

我遇到了同样的错误,原因很愚蠢 - 我没有权限提交到选定的仓库。我不知道我必须先进行以下步骤:

  1. fork选定的项目
  2. 在本地克隆仓库
  3. 在本地提交我的更改
  4. 将更改推送到我的github克隆
  5. 向上游请求拉取请求

https://help.github.com/categories/63/articles所述。


2
不是傻瓜,这是大多数第一次向公共存储库贡献的正确答案。 - DaReal
2
非常感谢。这是我第一次为公共存储库做出贡献。这是我的问题。 - MajinBoo

9
  1. 点击您的存储库
  2. 在右侧,单击“设置”
  3. 在左侧选项面板上,单击“协作者”
  4. 添加您在GitHub中认识的人的名称
  5. 单击“添加协作者”

此后我们的“Push到Git”正常工作了。


7

将其更改为

url=https://MichaelDrogalis@github.com/derekerdmann/lunch_call.git 

为了

url=ssh://git@github.com/derekerdmann/lunch_call.git

它可以工作!

在“@”之前不要忘记“git”。


它对我有用(在代理后面使用CentOS服务器和RStudio)。 首先设置代理:git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port 然后使用命令git remote set-url origin来切换地址。 - Alexandre georges


6

以下是解决方案

对于 Windows 用户,您可以在以下位置找到密钥:

控制面板 > 用户帐户 > 凭据管理器 > Windows 凭据 > 通用凭据

接下来,删除 Github 密钥。

对于 Mac 用户

1. 在 Finder 中搜索 Keychain Access 应用程序。

2. 在 Keychain Access 中搜索 github.com。

3. 找到 github.com 的 "internet password" 条目。

4. 根据需要编辑或删除该条目。


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