git error: gnutls_handshake() failed on push

2020-04-05 07:07发布

I have been using git for a while with no problems, then suddenly it started throwing this error when using git push:

error: gnutls_handshake() failed: A TLS packet with unexpected length was received. while accessing ... fatal: HTTP request failed

It was working fine, then suddenly it stopped.

What is the problem?

Thanks

标签: git
5条回答
We Are One
2楼-- · 2020-04-05 07:31

It seems there is a problem with the gnutls package. As a workaround, you can try to compile git with openssl. More info on how to accomplish this you can find here.

查看更多
▲ chillily
3楼-- · 2020-04-05 07:39

The linked discussion on askubuntu references a version number for git that may not match up with your own. Instead of these two lines:

sudo dpkg-source -x git_1.7.9.5-1.dsc
cd git_1.7.9.5 8.

you need to account for the version of git you're using. In my case, it was 1.8.xxxxx.

sudo dpkg-source -x git_<git-version-number>.dsc
cd git_<git-version-number>

An easy way to get around this is to just copy the first part of the command and then hit Tab to autocomplete. This may not work perfectly if you have recompiled before.

查看更多
霸刀☆藐视天下
4楼-- · 2020-04-05 07:39

In my case same error was caused by completely different thing.

Debian was upgraded from Wheezy to Jessie, and thus apache was upgraded 2.2.22 to 2.4.10. git was trying to push to https://www.example.com and it stopped working with error: gnutls_handshake() failed: A TLS packet with unexpected length was received

Turns out, www.example.com was resolving to both IPv4 and IPv6 addresses, and apache config was having <Virtualhost x.y.w.z:443> IPv4 address only. Changing that to <Virtualhost _default_:443> fixed the problem.

(just so if it helps somebody else with same problem... only found it after the tedious recompile of git with openssl didn't change anything at all)

查看更多
▲ chillily
5楼-- · 2020-04-05 07:41

This answer might help. I was surprised that the problems are nowhere to be linked together although the question is old.

Just to be sure the usefull info won't get lost, I copy a brief solution from the question:

hostname=XXX
port=443
trust_cert_file_location=`curl-config --ca`

sudo bash -c "echo -n | openssl s_client -showcerts -connect $hostname:$port 2>/dev/null  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >> $trust_cert_file_location"
查看更多
淡お忘
6楼-- · 2020-04-05 07:55

I have also faced the same issue which was fixed later by disabling my Kaspersky antivirus in my local machine. I hope this may be helpful to others. error report and solution

查看更多
登录 后发表回答