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

0
如果所有其他方法都失败了,只需确保您没有将项目存档。这就是我的问题,它会将整个解决方案置于只读模式。

0

当你没有在电子邮件或Github仓库账户中接受邀请链接时,会出现403错误(访问被拒绝)。

点击邀请链接后,您可以使用以下命令添加远程仓库:

git remote add <name> <url>
git push —set-upstream <repo_name> master

例子:

git remote add ProgrammingFoundationExam https://github.com/itprowhoami/ProgrammingFoundationExam.git
git push --set-upstream ProgrammingFoundationExam master

0

0
另一个可能的原因是,你可能超过了他们的计划限制。
要解决这个问题并恢复对仓库的写入访问权限,你可以选择升级你的账户计划,或者移除一些合作者。

0

如果以上解决方案都无法解决您的问题,请快速阅读以下答案[可能适用于您的情况]:

对于像我一样经历了所有这些[很棒的]答案但仍然无法推送提交的人,可能还有另一个失败的原因。

检查您的git存储库(无论它在哪里,GitHub,BitBucket等)是否正常。在我的情况下,花费了很多时间弄清楚我的问题是什么(甚至责怪PyCharm的新版本! :)),我意识到我做了一些愚蠢的事情,我的BitBucket存储库超过了2GB的限制,并自动变成只读存储库,这就是为什么我无法推送任何新提交的原因。而且,这正是导致您出现相同错误(403:无法访问URL)的原因。


0

之前我以另一个Github用户的身份登录(称为user1)。对于我的实际Github账户(称为user2),我能够在Github上克隆一个新创建的仓库,但我无法推送更改。

我尝试了以上提到的所有答案,包括从Windows凭据管理器中删除凭据,但都没有起作用。

最后,启动Github Windows应用程序才奏效。导航到“设置”->“选项”,然后登录所需的用户,在这种情况下是user2。

enter image description here


0
为用户提供写入权限。
在提供了权限之后,先拉取代码,然后再推送。

0

确保您有足够的权限将更改推送到代码库,如果有,请尝试运行以下命令

git config --global user.email youremail@domain.
git config --global user.name username
git config --global user.password yourpassword

希望这能帮助到某个人


0
这种情况可能是因为代码库被禁用了(代码库的所有者可以禁用它,或者如果账户没有支付费用,Github会禁用账户下的所有私有代码库)。
因此,您应该联系代码库的所有者,并告知他代码库已被禁用。

0

我遇到了类似的错误

致命错误:无法访问'https://gitlab.com/xxxx/yyyy.git/':请求的URL返回错误:403

我通过切换网络(更改IP)解决了这个问题。最初,我在我的系统中遇到了问题,然后我尝试使用新的网络(使用移动热点)并进行了git pull操作。

然后我又回到了主要的网络,我能够执行所有的git操作而没有任何问题。


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