AndroidStudio或IDEA中连接github失败:Can't login: Connect to api.github.com:443

时间:2022-10-12 15:52:43

一般情况下,在AndroidStudio中连接github,输入账号和密码,点击Test按钮,会连接成功。

有时候会出现如下错误:
Can’t login: Connect to api.github.com:443 [api.github.com/208.78.70.16] failed: Connection refused: connect
出现该错误是本地hosts文件中配置不正确导致的。

打开hosts文件:C:\Windows\System32\drivers\etc\hosts
查看hosts中是否包含208.78.70.16这个ip地址,如果有,把该ip地址注释掉即可,在最前面添加#即添加注释成功,如#208.78.70.16。

保存退出,再次点击Test按钮连接github,如果hosts中配置正确,应该是可以成功连接到github的。如下图:
AndroidStudio或IDEA中连接github失败:Can't login: Connect to api.github.com:443